Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <Stepper.h>
  2. #include <Servo.h>
  3. #include <LiquidCrystal.h>
  4.  
  5. #define stepsPerRevolution 48 // for stepper motor
  6. #define rs 7
  7. #define en 6
  8. #define d4 5
  9. #define d5 4
  10. #define d6 3
  11. #define d7 2
  12.  
  13. int redCount = 0 , greenCount = 0 , blueCount = 0 ;
  14.  
  15. // initialize the stepper library on pins 8 through 11:
  16. //Stepper myStepper(stepsPerRevolution, 8, 10 , 9 , 11);/
  17. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  18. Servo myservo;
  19.  
  20. enum {NO_COLOR , RED , GREEN , BLUE};
  21.  
  22. int getColor();
  23. void updateLCD();
  24.  
  25. void setup() {
  26. // put your setup code here, to run once:
  27. // myStepper.setSpeed(150);/
  28. myservo.attach(12);
  29. lcd.begin(16, 2);
  30. lcd.print("Red:0 Blue:0");
  31. lcd.setCursor(0, 1); // set the cursor to column 0, line 1
  32. lcd.print("Green:0");
  33. }
  34.  
  35. void loop() {
  36. // put your main code here, to run repeatedly:
  37. // myStepper.step(10 * stepsPerRevolution); // change later to start moving and stop at color sensor/
  38. int color = getColor();
  39.  
  40. if (color == RED) {
  41. myservo.write(0);
  42. // myStepper.step(20 * stepsPerRevolution);/
  43. redCount++;
  44. updateLCD();
  45. } else if (color == GREEN) {
  46. myservo.write(180);
  47. // myStepper.step(20 * stepsPerRevolution);/
  48. greenCount++;
  49. updateLCD();
  50. } else if (color == BLUE) {
  51. // myStepper.step(-20 * stepsPerRevolution); // -ve means move in the opposite direction/
  52. blueCount++;
  53. updateLCD();
  54. }
  55.  
  56. }
  57.  
  58. int getColor() {
  59.  
  60. // TODO: code for color sensor
  61. return 0;
  62. }
  63.  
  64. void updateLCD() {
  65.  
  66. lcd.setCursor(4, 0); // go to position of red number
  67. lcd.print(redCount);
  68.  
  69. lcd.setCursor(13, 0); // go to position of blue number
  70. lcd.print(blueCount);
  71.  
  72. lcd.setCursor(6, 1); // go to position of green number
  73. lcd.print(greenCount);
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement