Circuit Diagram
Components
- 1x Breadboard
- 1x RedBoard or Arduino Uno
- 1x Flex Sensor
- 1x RGB Led
- 1x 10k resistor
- 3 x 330Ω resistor
- Wires
Code
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
const int flexpin = 0;
void setup()
{
Serial.begin(9600);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop()
{
int flexposition;
// Input value from the analog pin.
flexposition =
analogRead(flexpin);
Serial.print("sensor: ");
Serial.print(flexposition);
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
if(flexposition>800) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
}
else if(flexposition>720) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
}
if(flexposition<700) {
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
}
else if(flexposition<720) {
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
}
}
Video
Hiç yorum yok:
Yorum Gönder