that my previous sketch
#include <ezButton.h>
#define LOOP_STATE_STOPPED 0
#define LOOP_STATE_STARTED 1
ezButton button(2); // create ezButton object that attach to pin 2;
ezButton button1(3); // create ezButton object that attach to pin 3;
ezButton button2(4); // create ezButton object that attach to pin 4;
int loopState = LOOP_STATE_STOPPED;
#define motor 19 // motor attached in relay attached to pin A5
#define vane1 18 // van 1 attached in relay attached to pin A4
#define vane2 17 // van 2 attached in relay attached to pin A3
#define vane3 16 // van 3 attached in relay attached to pin A2
#define vane4 15 // van 4 attached in relay attached to pin A1 // all output (A0,A1,A2,A3,A4,A5) go to ULN2003 to relays
#define fan 14 // fan attached in relay attached to pin A0
//#define bm1 2 // push_button 1 attached betwen pin 2 of arduino and earth
//#define bm2 3 // push_button 2 attached betwen pin 3 of arduino and earth
//#define bm3 4 // push_button 3 attached betwen pin 4 of arduino and earth
#define led1 5 // led 1 attached betwen pin 5 of arduino and earth series with 470 ohm resistor
#define led2 6 // led 2 attached betwen pin 6 of arduino and earth series with 470 ohm resistor
#define led3 7 // led 3 attached betwen pin 7 of arduino and earth series with 470 ohm resistor
// the leds is combined in button and i need to use them bliking the time of runing one of my program
#define buzz 8 // buzzer attached betwen pin 5 of arduino and earth (in real i run with bc547 )
int i; // variable for state of incriment and decriment for switching betwin program to other
int a = 1; // variable for store value of button 1
int b = 1; // variable for store value of button 2
int c = 1; // variable for store value of button 3
volatile byte state = LOW; // variable for store value for bliking led the time of runing loop
void blink() // loop bliking led
{
state =! state;
}
void pression() // this loop is an program for the first button 1 to do when is pressed for first time
{
digitalWrite(led1 ,blink); // i dont know what is the error her because is not bliking when program run and compiling not let me thath wrong
digitalWrite(buzz ,HIGH);
delay(500);
digitalWrite(buzz , LOW);
digitalWrite(motor,HIGH);
digitalWrite(fan ,HIGH);
digitalWrite(vane2,HIGH);
delay(12000);
digitalWrite(motor,LOW);
digitalWrite(fan ,LOW);
digitalWrite(vane2,LOW);
delay(30000);
digitalWrite(vane1,HIGH);
delay(20000);
digitalWrite(vane1,LOW);
digitalWrite(led1 ,LOW);
digitalWrite(buzz ,HIGH);
delay(500);
digitalWrite(buzz ,LOW);
}
void vaccum() // this loop is an program for the first button 2 to do when is pressed for first time
{
digitalWrite(led2 ,blink); // i dont know what is the error her because is not bliking when program run and compiling not let me thath wrong
digitalWrite(buzz ,HIGH);
delay(500);
digitalWrite(buzz, LOW);
digitalWrite(motor,HIGH);
digitalWrite(fan ,HIGH);
digitalWrite(vane1,HIGH);
digitalWrite(vane3,HIGH);
delay(35000);
digitalWrite(vane3,LOW);
delay(25000);
digitalWrite(vane3,HIGH);
delay(15000);
digitalWrite(vane4,HIGH);
delay(10000);
digitalWrite(vane4,LOW);
digitalWrite(vane2,HIGH);
delay(10000);
digitalWrite(motor,LOW);
digitalWrite(fan ,LOW);
digitalWrite(vane1,LOW);
digitalWrite(vane3,LOW);
delay(90000);
digitalWrite(led2 ,LOW);
digitalWrite(vane2,LOW);
digitalWrite(buzz ,HIGH);
delay(500);
digitalWrite(buzz ,LOW);
}
void pressionp() // this loop is an program for the first button 3 to do when is pressed for first time
{
digitalWrite(led3 ,blink); // i dont know what is the error her because is not bliking when program run and compiling not let me thath wrong
digitalWrite(buzz ,HIGH);
delay(500);
digitalWrite(buzz , LOW);
digitalWrite(motor,HIGH);
digitalWrite(fan ,HIGH);
digitalWrite(vane2,HIGH);
delay(12000);
digitalWrite(motor ,LOW);
digitalWrite(fan ,LOW);
digitalWrite(vane2 ,LOW);
delay(24000);
digitalWrite(vane1,HIGH);
delay(20000);
digitalWrite(vane1 ,LOW);
digitalWrite(led3 ,LOW);
digitalWrite(buzz ,HIGH);
delay(500);
digitalWrite(buzz ,LOW);
}
void off() // this loop is an program for the all button 1,2 and 3 to do when is pressed for second time
{
digitalWrite(motor,LOW);
digitalWrite(vane1,HIGH);
digitalWrite(vane2,HIGH);
digitalWrite(vane3,HIGH);
digitalWrite(vane4,HIGH);
digitalWrite(fan ,LOW);
digitalWrite(led1 ,LOW);
digitalWrite(led2 ,LOW);
digitalWrite(led3 ,LOW);
digitalWrite(buzz ,LOW);
delay(2000);
digitalWrite(motor,LOW);
digitalWrite(vane1,LOW);
digitalWrite(vane2,LOW);
digitalWrite(vane3,LOW);
digitalWrite(vane4,LOW);
digitalWrite(fan ,LOW);
digitalWrite(led1 ,LOW);
digitalWrite(led2 ,LOW);
digitalWrite(led3 ,LOW);
digitalWrite(buzz ,LOW);
}
void setup()
{
button.setDebounceTime(50); // set debounce time to 50 milliseconds
button1.setDebounceTime(50); // set debounce time to 50 milliseconds
button2.setDebounceTime(50); // set debounce time to 50 milliseconds
// pinMode(bm1 ,INPUT_PULLUP);
// pinMode(bm2 ,INPUT_PULLUP);
// pinMode(bm3 ,INPUT_PULLUP);
pinMode(motor ,OUTPUT);
pinMode(vane1 ,OUTPUT);
pinMode(vane2 ,OUTPUT);
pinMode(vane3 ,OUTPUT);
pinMode(vane4 ,OUTPUT);
pinMode(fan ,OUTPUT);
pinMode(led1 ,OUTPUT);
pinMode(led2 ,OUTPUT);
pinMode(led3 ,OUTPUT);
pinMode(buzz ,OUTPUT);
}
void loop()
{
button.loop(); // MUST call the loop() function first
if (button.isPressed())
{
if (loopState == LOOP_STATE_STOPPED)
loopState = LOOP_STATE_STARTED;
else // if(loopState == LOOP_STATE_STARTED)
loopState = LOOP_STATE_STOPPED;
off();
}
if (loopState == LOOP_STATE_STARTED)
{
pression();
}
if (button1.isPressed())
{
if (loopState == LOOP_STATE_STOPPED)
loopState = LOOP_STATE_STARTED;
else // if(loopState == LOOP_STATE_STARTED)
loopState = LOOP_STATE_STOPPED;
off();
}
if (loopState == LOOP_STATE_STARTED)
{
vaccum();
if (button2.isPressed())
{
if (loopState == LOOP_STATE_STOPPED)
loopState = LOOP_STATE_STARTED;
else // if(loopState == LOOP_STATE_STARTED)
loopState = LOOP_STATE_STOPPED;
off();
}
if (loopState == LOOP_STATE_STARTED)
{
pressionp();
} }
}
that my rest now
my sketch with millis function is loses because my laptop is turn off without saving my data