11 Mayıs 2015 Pazartesi

Touchscreen with leds


Leds with Soft Potentiometer Circuit Design
This circuit is designed for switching leds by values that come from soft potentiometer.
Values are mapped according to the number of leds.
Code are shown in below :

/*soft potentiometer with leds*/
const int SENSOR_PIN = 0;
 byte ledPins [7];


void setup()
{
  int i;
  Serial.begin(9600);
  for (i=0;i<7;i++){
    ledPins[i] = i+2;
    pinMode(ledPins[i],OUTPUT);
  }
}
void loop(){
  int sensorValue ;
  sensorValue = analogRead(SENSOR_PIN);
  Serial.print("Sensor Value ");
  Serial.println(sensorValue);
  int openPin = map(sensorValue,0,1023,-1,7);
  Serial.print("pin is ");
  Serial.println(openPin);
  int i;
  for(i=0;i<7;i++){
    if(i == openPin){
      digitalWrite(ledPins[i],HIGH);
    }else{
      digitalWrite(ledPins[i],LOW);
  }
  }
}

Leds and softpotentiometer connection




Hiç yorum yok:

Yorum Gönder