5 Nisan 2015 Pazar

Arduino Experiment 2: Reading a Potentiometer - Modify (One increases while another decreases- )

Definition : In this circuit we connected 2 leds and 1 potentiometer to arduino and control leds while frequency of red led increases and green decreases and vice versa depending on potentiometer's value.

Circuit Diagram


Components
1 x 10 k Potentiometer
2 x Led
Wires

Code

int sensorPin = 0;    // The potentiometer is connected to
                      // analog pin 0
int ledPin = 12;
int ledPin2 = 13;      // The LED is connected to digital pin 13



void setup() // this function runs once when the sketch starts up
{

  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);


}


void loop() // this function runs repeatedly after setup() finishes
{

  int sensorValue;


  sensorValue = analogRead(sensorPin);  

  digitalWrite(ledPin, HIGH);     // Turn the LED on

  delay(sensorValue);             // Pause for sensorValue
    digitalWrite(ledPin, LOW);      // Turn the LED off

  delay(sensorValue);

    digitalWrite(ledPin2, HIGH);
    delay(1/sensorValue);
                                  // milliseconds

             // Pause for sensorValue
                                  // milliseconds
                               
    digitalWrite(ledPin2, LOW);      // Turn the LED off

  delay(1/sensorValue);


}


Video





Hiç yorum yok:

Yorum Gönder