There are three leds that are composed of a green, a yellow and a red led (like a traffic lamb). The flex sensor provides us to be able to switch between these three leds and ligth one of them at a time.
The circuit diagrams (one made on digital environment, the other one is the implemented) and the datasheet of shift register can be seen below:
Digital Drawed Circuit
Implemented Circuit
Here is a video available to see the outputs and how the system works:
Arduino Code :
/* Can KAVALOĞLU */ int greenPin = 8; int yellowPin = 9; int redPin = 10; int flexValue; void setup(){ pinMode(flexPin, INPUT); pinMode(greenPin, OUTPUT); pinMode(yellowPin, OUTPUT); pinMode(redPin, OUTPUT); Serial.begin(9600); } void loop(){ flexValue = analogRead(flexPin); flexValue = constrain(flexValue, 720, 950); flexValue = map(flexValue, 720, 950, 0, 1024); if(flexValue < 350){ digitalWrite(greenPin, HIGH); digitalWrite(yellowPin, LOW); digitalWrite(redPin, LOW); } else if(flexValue < 600){ digitalWrite(greenPin, LOW); digitalWrite(yellowPin, HIGH); digitalWrite(redPin, LOW); } else{ digitalWrite(greenPin, LOW); digitalWrite(yellowPin, LOW); digitalWrite(redPin, HIGH); } Serial.println(flexValue); delay(200); }
Hiç yorum yok:
Yorum Gönder