Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo; //create servo object to control a servo
- const int potpin = A0; //analog pin used to connect the potentiometer
- int value; //variable to read the value from the analog pin
- const int whiteled = 5;
- const int yellowled = 4;
- const int blueled = 3;
- void setup()
- {
- pinMode (potpin, INPUT);
- Serial.begin (9600);
- myservo.attach(12);//attaches the servo on pin 12 to the servo object
- pinMode (whiteled, OUTPUT);
- pinMode (yellowled, OUTPUT);
- pinMode (blueled, OUTPUT);
- }
- void loop()
- {
- value = analogRead (potpin);
- value = map(value, 0, 1023, 0, 180);
- Serial.println (value);
- myservo.write (value); //write into servo the value of the potentiometer, makes servo move
- delay (15);
- if (value < 90)
- {
- digitalWrite (whiteled, HIGH);
- digitalWrite (yellowled, LOW);
- digitalWrite (blueled, LOW);
- }
- else if (value == 90)
- {
- digitalWrite (whiteled, LOW);
- digitalWrite (yellowled, HIGH);
- digitalWrite (blueled, LOW);
- }
- else if (value > 90)
- {
- digitalWrite (whiteled, LOW);
- digitalWrite (yellowled, LOW);
- digitalWrite (blueled, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement