Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LED_RED 2
- #define LED_GREEN 3
- #define PIN_SW 12
- #define PIN_MOSFET 8
- #define PIN_POT A7
- #define TIME_MIN 5
- #define TIME_MAX 100
- void setup() {
- // put your setup code here, to run once:
- pinMode(PIN_LED_RED, OUTPUT);
- pinMode(PIN_LED_GREEN, OUTPUT);
- pinMode(PIN_MOSFET, OUTPUT);
- pinMode(PIN_SW, INPUT_PULLUP);
- Serial.begin(115200);
- Serial.println("started");
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int potVal = analogRead(PIN_POT);
- Serial.print("Pot raw value ");
- Serial.print(potVal);
- int delayTime = map(potVal, 0, 1022, TIME_MIN, TIME_MAX);
- Serial.print(" \tdelay ");
- Serial.print(delayTime);
- if(digitalRead(PIN_SW) == LOW){
- Serial.print(" \t sw on ");
- SW_ON(delayTime);
- delay(1000);
- }else{
- Serial.print(" \t sw off ");
- }
- Serial.println();
- delay(100);
- }
- void SW_ON(int duration)
- {
- digitalWrite(PIN_LED_RED, HIGH);
- digitalWrite(PIN_MOSFET, HIGH);
- delay(duration*0.5);
- digitalWrite(PIN_MOSFET, LOW);
- delay(500);
- digitalWrite(PIN_MOSFET, HIGH);
- delay(duration);
- digitalWrite(PIN_MOSFET, LOW);
- digitalWrite(PIN_LED_RED, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement