Advertisement
DrAungWinHtut

weldingmachine1.ino

Nov 3rd, 2022
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Programmer Dr. Aung Win Htut
  2. // Founder of Green Hackers
  3. #include <Adafruit_LiquidCrystal.h>
  4.  
  5.  
  6. const int push_button = 11;
  7. const int up_button = 12;
  8. const int down_button = 13;
  9. const int buzzer = 10;
  10. const int relay = 2;
  11.  
  12. int push_button_state=LOW;
  13. int push_button_last_state=LOW;
  14. int up_button_state=LOW;
  15. int up_button_last_state=LOW;
  16. int down_button_state=LOW;
  17. int down_button_last_state=LOW;
  18.  
  19. unsigned long lastDebounceTime_push_button = 0;  // the last time the output pin was toggled
  20. unsigned long lastDebounceTime_up_button = 0;
  21. unsigned long lastDebounceTime_down_button = 0;
  22. unsigned long debounceDelay = 500;    // the debounce time; increase if the output flickers
  23.  
  24. int seconds = 0;
  25. int time_delay = 0; //0.3 ms
  26.  
  27. Adafruit_LiquidCrystal lcd_1(0);
  28.  
  29. void setup()
  30. {
  31.   pinMode(push_button,INPUT);
  32.   pinMode(up_button,INPUT);
  33.   pinMode(down_button,INPUT);
  34.   pinMode(relay,OUTPUT); //relay
  35.   pinMode(buzzer,OUTPUT); //buzzer
  36.  
  37.   lcd_1.begin(16, 2);
  38.   lcd_1.setCursor(0, 0);   
  39.   lcd_1.print("    Kyaw Electronics");
  40.   lcd_1.setCursor(1, 1);
  41.   lcd_1.print("Spot Time ");
  42.   Serial.begin(9600);
  43. }
  44.  
  45. void loop()
  46. {
  47.    // read the state of the switch into a local variable:
  48.   int reading_push_button = digitalRead(push_button);
  49.   Serial.print("Push button state "); Serial.println(reading_push_button);
  50.   int reading_up_button = digitalRead(up_button);
  51.   int reading_down_button = digitalRead(down_button);
  52.  
  53.   // check to see if you just pressed the button
  54.   // (i.e. the input went from LOW to HIGH), and you've waited long enough
  55.   // since the last press to ignore any noise:
  56.  
  57.   // If the switch changed, due to noise or pressing:
  58.   if (reading_push_button != push_button_last_state) {
  59.     // reset the debouncing timer
  60.     Serial.print("Push button state changed "); Serial.println(reading_push_button);
  61.     lastDebounceTime_push_button = millis();
  62.   }
  63.  
  64.   if ((millis() - lastDebounceTime_push_button) > debounceDelay) {
  65.     // whatever the reading is at, it's been there for longer than the debounce
  66.     // delay, so take it as the actual current state:
  67.     Serial.print("Debounce over "); Serial.println(reading_push_button);
  68.     // if the button state has changed:
  69.     if (reading_push_button != push_button_state) {
  70.       push_button_state = reading_push_button;
  71.        
  72.  
  73.       // only toggle the LED if the new button state is HIGH
  74.       if (push_button_state == HIGH) {
  75.         //relay on after timer
  76.         digitalWrite(relay,HIGH);
  77.         digitalWrite(buzzer,HIGH);
  78.         delay(time_delay);
  79.         digitalWrite(relay,LOW);
  80.         digitalWrite(buzzer,LOW);
  81.       }
  82.     }
  83.   }
  84.  
  85.   // If the switch changed, due to noise or pressing:
  86.   if (reading_up_button != up_button_last_state) {
  87.     // reset the debouncing timer
  88.     lastDebounceTime_up_button = millis();
  89.    
  90.   }
  91.  
  92.   if ((millis() - lastDebounceTime_up_button) > debounceDelay) {
  93.     // whatever the reading is at, it's been there for longer than the debounce
  94.     // delay, so take it as the actual current state:
  95.    
  96.     // if the button state has changed:
  97.     if (reading_up_button != up_button_state) {
  98.       up_button_state = reading_up_button;
  99.        lcd_1.setCursor(11, 1); 
  100.        lcd_1.print("p");
  101.       // only toggle the LED if the new button state is HIGH
  102.       if (up_button_state == HIGH) {
  103.         //Increace delay time by 1 ms
  104.         time_delay++;
  105.         lcd_1.setCursor(11, 1);
  106.         lcd_1.print(time_delay);
  107.       }
  108.     }
  109.   }
  110.  
  111.     // If the switch changed, due to noise or pressing:
  112.   if (reading_down_button != down_button_last_state) {
  113.     // reset the debouncing timer
  114.     lastDebounceTime_down_button = millis();
  115.   }
  116.  
  117.   if ((millis() - lastDebounceTime_down_button) > debounceDelay) {
  118.     // whatever the reading is at, it's been there for longer than the debounce
  119.     // delay, so take it as the actual current state:
  120.  
  121.     // if the button state has changed:
  122.     if (reading_down_button != down_button_state) {
  123.       down_button_state = reading_down_button;
  124.  
  125.       // only toggle the LED if the new button state is HIGH
  126.       if (reading_down_button == HIGH) {
  127.         //Decreace delay time by 1 ms
  128.         time_delay--;
  129.         lcd_1.setCursor(11, 1);
  130.         lcd_1.print(time_delay);
  131.       }
  132.     }
  133.   }
  134.  
  135.  
  136.  
  137.   // save the reading. Next time through the loop, it'll be the lastButtonState:
  138.   push_button_state = reading_push_button;
  139.   up_button_state   = reading_up_button;
  140.   down_button_state = reading_down_button;
  141.  
  142.   lcd_1.setCursor(11, 1);  
  143.   lcd_1.print(time_delay);
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement