Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. #include <rgb_lcd.h>
  2. #include <Stepper.h>
  3. #include <Wire.h>
  4.  
  5. const int OK = 2;
  6. const int buzzer = 3;
  7. const int button_INCRE = 4;
  8. const int button_DECRE = 5;
  9.  
  10. //Change this according to one revolution steps
  11. #define SIZE 32
  12. rgb_lcd lcd;
  13.  
  14. const int stepsPerRevolution = 200;
  15. Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
  16. int temp;
  17.  
  18. void setup() {
  19. pinMode(8,OUTPUT);
  20. pinMode(9,OUTPUT);
  21. pinMode(10,OUTPUT);
  22. pinMode(11,OUTPUT);
  23. pinMode(2,INPUT_PULLUP);
  24. pinMode(4,INPUT_PULLUP);
  25. pinMode(5,INPUT_PULLUP);
  26. lcd.begin(16, 2);
  27. lcd.setRGB(0,0,255);
  28. Serial.begin(9600);
  29. }
  30. void setup1(){
  31. temp=0;
  32. lcd.print("WELCOME");
  33. lcd.setCursor(0,1);
  34. lcd.print("PRESS OK");
  35. while(digitalRead(OK)==1){}
  36. myTone(buzzer,1000, 400);
  37. lcd.clear();
  38. lcd.setRGB(255,10,10);
  39. lcd.print("Enter STEPS");
  40. lcd.setCursor(0,1);
  41. lcd.print(temp);
  42. while(digitalRead(OK)==1){
  43. if(digitalRead(button_INCRE)==0){
  44. temp++;
  45. lcd.setCursor(0,1);
  46. lcd.print(temp);
  47. delay(150);
  48. }
  49. if(digitalRead(button_DECRE)==0){
  50. temp--;
  51. lcd.setCursor(0,1);
  52. lcd.print(temp);
  53. delay(150);
  54. }
  55. }
  56. myTone(buzzer,1000, 400);
  57. lcd.clear();
  58. lcd.setRGB(255,255,0);
  59. lcd.print("SPEED");
  60. int sensorReading=1;
  61. while(digitalRead(OK)==1){
  62. if(digitalRead(button_INCRE)==0){
  63. sensorReading++;
  64. delay(150);
  65. }
  66. if((digitalRead(button_DECRE)==0)){
  67. sensorReading--;
  68. delay(150);
  69. }
  70. lcd.clear();
  71. lcd.print("SPEED(1-60)");
  72. lcd.setCursor(0,1);
  73. lcd.print(sensorReading);
  74. delay(100);
  75. }
  76. myTone(buzzer,1000, 200);
  77. lcd.clear();
  78. lcd.setRGB(255,10,150);
  79. lcd.print("PRESS OK");
  80. lcd.setCursor(0,1);
  81. lcd.print("FOR CONT..");
  82. myStepper.setSpeed(sensorReading);
  83. delay(400);
  84. while(digitalRead(OK)==1){}
  85. myTone(buzzer,1000, 300);
  86. }
  87. void turn(){
  88. int i=0;
  89. while(i<=SIZE*temp){
  90. myStepper.step(1);
  91. lcd.setCursor(0,1);
  92. lcd.print(int(i/SIZE));
  93. i++;
  94. }
  95. lcd.clear();
  96. lcd.print("DONE!");
  97. lcd.setCursor(0,1);
  98. lcd.print("PRESS BUTTON");
  99. while(digitalRead(OK)==1){}
  100. myTone(buzzer,1000, 200);
  101. lcd.clear();
  102. lcd.print("CONFORM");
  103. lcd.setCursor(0,1);
  104. lcd.print("PRESS OK");
  105. while(digitalRead(OK)==1){}
  106. myTone(buzzer,1000, 200);
  107. }
  108. void myTone(byte pin, uint16_t frequency, uint16_t duration){
  109. unsigned long startTime=millis();
  110. unsigned long halfPeriod= 1000000L/frequency/2;
  111. pinMode(pin,OUTPUT);
  112. while (millis()-startTime< duration)
  113. {
  114. digitalWrite(pin,HIGH);
  115. delayMicroseconds(halfPeriod/8);
  116. digitalWrite(pin,LOW);
  117. delayMicroseconds(halfPeriod/8);
  118. }
  119. pinMode(pin,INPUT);
  120. }
  121. void loop() {
  122. setup1();
  123. lcd.clear();
  124. lcd.setRGB(255,10,10);
  125. lcd.print("STEPS");
  126. lcd.setCursor(0,1);
  127. turn();
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement