Robert_l

zgrzewarka v0

Mar 15th, 2021
494
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define LED_RED 2
  2. #define LED_GREEN 3
  3. #define PIN_SW 12
  4. #define PIN_MOSFET 8
  5. #define PIN_POT A7
  6.  
  7. #define TIME_MIN 5
  8. #define TIME_MAX 100
  9.  
  10. void setup() {
  11.   // put your setup code here, to run once:
  12.   pinMode(PIN_LED_RED, OUTPUT);
  13.   pinMode(PIN_LED_GREEN, OUTPUT);
  14.   pinMode(PIN_MOSFET, OUTPUT);
  15.   pinMode(PIN_SW, INPUT_PULLUP);
  16.   Serial.begin(115200);
  17.   Serial.println("started");
  18. }
  19.  
  20. void loop() {
  21.   // put your main code here, to run repeatedly:
  22.  int potVal = analogRead(PIN_POT);
  23.  Serial.print("Pot raw value ");
  24.  Serial.print(potVal);
  25.  
  26.  int delayTime = map(potVal, 0, 1022, TIME_MIN, TIME_MAX);
  27.  
  28.  Serial.print(" \tdelay ");
  29.  Serial.print(delayTime);
  30.  
  31.   if(digitalRead(PIN_SW) == LOW){
  32.     Serial.print(" \t sw on ");
  33.     SW_ON(delayTime);
  34.     delay(1000);
  35.   }else{
  36.     Serial.print(" \t sw off ");
  37.   }
  38.  
  39.   Serial.println();
  40.  delay(100);
  41. }
  42. void SW_ON(int duration)
  43. {
  44.   digitalWrite(PIN_LED_RED, HIGH);
  45.   digitalWrite(PIN_MOSFET, HIGH);
  46.   delay(duration*0.5);
  47.   digitalWrite(PIN_MOSFET, LOW);
  48.  
  49.   delay(500);
  50.  
  51.   digitalWrite(PIN_MOSFET, HIGH);
  52.   delay(duration);
  53.   digitalWrite(PIN_MOSFET, LOW);
  54.   digitalWrite(PIN_LED_RED, LOW);
  55. }
RAW Paste Data