Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- int i;
- Servo n1;
- String color;
- void setup(){
- Serial.begin(9600);
- n1.attach(6);
- pinMode(2,OUTPUT);
- pinMode(3,OUTPUT);
- pinMode(6,OUTPUT);
- }
- void loop(){
- Serial.println("Enter color: ");
- while(Serial.available()==0){
- }
- color=Serial.readString();
- if (color=="red"){
- digitalWrite(2,HIGH);
- n1.write(25);
- for (i=25;i<=175;i=i+2){
- n1.write(i);
- }
- delay(2500);
- digitalWrite(2,LOW);
- }
- else if (color=="orange"){
- digitalWrite(3,HIGH);
- n1.write(175);
- for (i=175;i>=25175;i=i-2){
- n1.write(i);
- }
- delay(2500);
- digitalWrite(3,LOW);
- }
- }
Add Comment
Please, Sign In to add comment