Guest User

Untitled

a guest
Jun 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <Servo.h>
  2. int i;
  3. Servo n1;
  4.  
  5. String color;
  6. void setup(){
  7.  
  8. Serial.begin(9600);
  9. n1.attach(6);
  10. pinMode(2,OUTPUT);
  11. pinMode(3,OUTPUT);
  12. pinMode(6,OUTPUT);
  13.  
  14.  
  15. }
  16.  
  17.  
  18. void loop(){
  19.  
  20. Serial.println("Enter color: ");
  21.  
  22. while(Serial.available()==0){
  23. }
  24. color=Serial.readString();
  25.  
  26. if (color=="red"){
  27. digitalWrite(2,HIGH);
  28. n1.write(25);
  29. for (i=25;i<=175;i=i+2){
  30. n1.write(i);
  31. }
  32. delay(2500);
  33. digitalWrite(2,LOW);
  34. }
  35. else if (color=="orange"){
  36. digitalWrite(3,HIGH);
  37. n1.write(175);
  38.  
  39. for (i=175;i>=25175;i=i-2){
  40. n1.write(i);
  41. }
  42. delay(2500);
  43. digitalWrite(3,LOW);
  44. }
  45. }
Add Comment
Please, Sign In to add comment