Guest User

Untitled

a guest
Dec 8th, 2019
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5. #include <Stepper.h>
  6. LiquidCrystal_I2C lcd(0x27, 16, 2);
  7. const int stepsPerRevolution = 1028;
  8.  
  9.  
  10. Stepper myStepper = Stepper(stepsPerRevolution, 9, 11, 10, 12);
  11. void setup() {
  12. //Set the speed to 5 rpm:
  13. pinMode(2, OUTPUT);
  14. pinMode(3, OUTPUT);
  15. pinMode(4, OUTPUT);
  16. pinMode(5, OUTPUT);
  17. pinMode(A3, INPUT);
  18. pinMode(A2, INPUT);
  19. pinMode(A1, INPUT);
  20. pinMode(A0, INPUT);
  21. pinMode(6, INPUT);
  22. pinMode(7, INPUT);
  23. myStepper.setSpeed(10);
  24. lcd.begin();
  25.  
  26. // Turn on the blacklight and print a message.
  27. lcd.backlight();
  28. lcd.print("Imeskite moneta");
  29. // Begin Serial communication at a baud rate of 9600:
  30. Serial.begin(9600);
  31. }
  32. boolean moneta = false;
  33. boolean iskrito = false;
  34. int daiktas = -1;
  35. void loop() {
  36. int reading = analogRead(A3);
  37. Serial.println(reading);
  38.  
  39. if(digitalRead(6) == LOW){
  40. moneta = true;
  41. Serial.write("HIGH");
  42. lcd.clear();
  43. lcd.print("Pasirinkite");
  44. }
  45.  
  46. if(moneta){
  47. if(analogRead(A3) >= 1000){
  48. digitalWrite(2, HIGH);
  49. daiktas = 1;
  50. }
  51. /* if(analogRead(A2) >= 1000){
  52. digitalWrite(3, HIGH);
  53. daiktas = 2;
  54. }
  55. if(analogRead(A1) >= 1000){
  56. digitalWrite(4, HIGH);
  57. daiktas = 3;
  58. }
  59. if(analogRead(A0) >= 1000){
  60. digitalWrite(5, HIGH);
  61. daiktas = 4;
  62. }*/
  63. }
  64. if(daiktas != -1){
  65. lcd.clear();
  66. lcd.print("Aciu, kad pirkote");
  67. lcd.setCursor(0,1);
  68. lcd.print("produktas:");
  69. //Serial.write(daiktas);
  70. lcd.setCursor(10,1);
  71. lcd.print(daiktas);
  72. }
  73. while(moneta && !iskrito && daiktas != -1){
  74. myStepper.step(128);
  75. if(digitalRead(7) == LOW){
  76. iskrito = true;
  77. }
  78. }
  79. if(moneta && iskrito && daiktas != -1){
  80. lcd.clear();
  81. lcd.print("Imeskite moneta");
  82. moneta = false;
  83. iskrito = false;
  84. daiktas = -1;
  85. digitalWrite(2, LOW);
  86. digitalWrite(3, LOW);
  87. digitalWrite(4, LOW);
  88. digitalWrite(5, LOW);
  89. }
  90. delay(100);
  91. }
RAW Paste Data