Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int voltagepin = A1;
- int powerswitch = 1;
- int mains = 0;
- int shutmedown = 4;
- void setup() {
- // put your setup code here, to run once:
- //Set Pin In/Out
- pinMode(powerswitch, OUTPUT);
- pinMode(shutmedown, OUTPUT);
- pinMode(voltagepin, INPUT);
- pinMode(mains, INPUT);
- delay(5000);
- bootup();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- if (!digitalRead(mains) && digitalRead(powerswitch) && analogRead(voltagepin)<402 ){
- digitalWrite(shutmedown,HIGH);
- delay(25000);
- digitalWrite(powerswitch,LOW);
- digitalWrite(shutmedown,LOW);
- delay(5000);
- }
- if(!digitalRead(powerswitch) && analogRead(voltagepin)>400 && digitalRead(mains)){
- digitalWrite(powerswitch,HIGH);
- }
- delay(10);
- }
- void bootup()
- {
- bool flag = false;
- while( flag == false ) //while charging lock in loop till voltage is above ref and mains is on
- {
- flag = digitalRead(mains) && analogRead(voltagepin)>400;
- //Karl Agius was here ^^^^^^^^^
- delay(500);//little wait
- }
- //Once Flag true Power On
- digitalWrite(powerswitch,HIGH);
- delay(10000); //bootup time
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement