Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // when compiling for attiny erase serial print and change pin numbers
- // relay pin
- #define relay_PIN0 0 // 0
- #define relay_PIN1 0
- #define relay_PIN2 0
- #define relay_PIN3 0
- #define relay_PIN4 0
- #define relay_PIN5 0
- // for counting
- int increasetempbutton = 3; // switch is connected to pin 4
- int va;// variable for reading the pin status
- int buttonState2; // variable to hold the button state
- int buttonPresses = 0; // how many times the button has been pressed
- int count;
- int decreasetempbutton = 2; // switch is connected to pin 4
- int buttonState3;
- int va2;// variable for reading the pin status
- //button to make count go to zero
- int button = 5; // the number of the pushbutton pin
- int buttonState = 0; // variable for reading the pushbutton status
- // debouce
- long lastDebounceTime = 0; // the last time the output pin was toggled
- long debounceDelay = 50; // the debounce time; increase if the output flickers
- // for the timing on and off
- #define relay_ON1 1000 //milliseconds
- #define relay_OFF1 10000
- #define relay_ON2 1000 //milliseconds
- #define relay_OFF2 5000
- #define relay_ON3 2000 //milliseconds
- #define relay_OFF3 3000
- #define relay_ON4 2000 //milliseconds
- #define relay_OFF4 2000
- unsigned long ms1; //time from millis()
- unsigned long msLast1; //last time the LED changed state
- unsigned long ms2; //time from millis()
- unsigned long msLast2; //last time the LED changed state
- unsigned long ms3; //time from millis()
- unsigned long msLast3; //last time the LED changed state
- unsigned long ms4; //time from millis()
- unsigned long msLast4; //last time the LED changed state
- boolean relayState1; //current LED state
- boolean relayState2; //current LED state
- boolean relayState3;
- boolean relayState4; //current LED state
- boolean replay0 = true; // to blink once
- boolean replay1 = true; // to blink once
- boolean replay2 = true; // to blink once
- boolean replay3 = true; // to blink once
- boolean replay4 = true; // to blink once
- boolean replay5 = true; // to blink once
- void setup(void)
- {
- pinMode(relay_PIN0, OUTPUT);
- pinMode(relay_PIN1, OUTPUT);
- pinMode(relay_PIN2, OUTPUT);
- pinMode(relay_PIN3, OUTPUT);
- pinMode(relay_PIN4, OUTPUT);
- pinMode(relay_PIN5, OUTPUT);
- pinMode(4, OUTPUT);
- pinMode(13, OUTPUT);
- pinMode(button, INPUT);
- pinMode(increasetempbutton, INPUT);
- pinMode(decreasetempbutton, INPUT);
- buttonState2 = digitalRead(increasetempbutton); // read the initial state
- buttonState3 = digitalRead(decreasetempbutton);
- buttonState = digitalRead(button);
- Serial.begin(9600);
- }
- void loop(void)
- {
- if (buttonState == HIGH) {
- digitalWrite(13, HIGH);
- }
- buttonState2 = va;
- buttonState3 = va2;
- count = buttonPresses;
- Serial.println(count);
- ms1 = millis();
- ms2 = millis();
- ms3 = millis();
- ms4 = millis();
- va = digitalRead(increasetempbutton);
- if (va != buttonState2) {
- if (va == LOW) {
- buttonPresses++ ;
- }
- }
- va2 = digitalRead(decreasetempbutton);
- if (va2 != buttonState3) {
- if (va2 == LOW) {
- buttonPresses-- ;
- }
- }
- //blink code and count this make the count go to 0 again
- if (count > 5) {
- buttonPresses--;
- buttonPresses--;
- buttonPresses--;
- buttonPresses--;
- buttonPresses--;
- buttonPresses--;
- }
- if (count < 0 ) {
- buttonPresses++;
- buttonPresses++;
- buttonPresses++;
- buttonPresses++;
- buttonPresses++;
- buttonPresses++;
- }
- if (count == 0) {
- digitalWrite(relay_PIN0, LOW);
- if (replay0 == true) {
- replay0 = false;
- replay1 = true;
- replay5 = true;
- }
- }
- if (count == 1) {
- if (ms1 - msLast1 > (relayState1 ? relay_ON1 : relay_OFF1)) {
- digitalWrite(relay_PIN1, relayState1 = !relayState1);
- msLast1 = ms1; }
- if (replay1 == true) {
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(150); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(150);
- replay1 = false;
- }
- replay2 = true;
- replay0 = true;
- }
- if (count == 2) {
- if (ms2 - msLast2 > (relayState2 ? relay_ON2 : relay_OFF2)) {
- digitalWrite(relay_PIN2, relayState2 = !relayState2);
- msLast2 = ms2; }
- if(replay2 == true){
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(150); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(150);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(150); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(150);
- replay2 = false;
- }
- replay1 = true;
- replay3 = true;
- }
- if (count == 3) {
- if (ms3 - msLast3 > (relayState3 ? relay_ON3 : relay_OFF3)) {
- digitalWrite(relay_PIN3, relayState3 = !relayState3);
- msLast3 = ms3;
- }
- if(replay3 == true){
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(150); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(150);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(150); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(150);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(150); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(150);
- replay3 = false;
- }
- replay2 = true;
- replay4 = true;
- }
- if (count == 4) {
- if (ms4 - msLast4 > (relayState4 ? relay_ON4 : relay_OFF4)) {
- digitalWrite(relay_PIN4, relayState4 = !relayState4);
- msLast4 = ms4;
- }
- if (replay4 == true)
- {
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- replay4 = false;
- }
- replay3 = true;
- replay5 = true;
- }
- if (count == 5) {
- digitalWrite(relay_PIN0, LOW);
- if(replay5 == true){
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(250); // wait for a second
- digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
- delay(250);
- replay5 = false;
- }
- replay4 = true;
- replay0 = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement