Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. int voltagepin = A1;
  2. int powerswitch = 1;
  3. int mains = 0;
  4. int shutmedown = 4;
  5.  
  6. void setup() {
  7. // put your setup code here, to run once:
  8. //Set Pin In/Out
  9. pinMode(powerswitch, OUTPUT);
  10. pinMode(shutmedown, OUTPUT);
  11. pinMode(voltagepin, INPUT);
  12. pinMode(mains, INPUT);
  13. delay(5000);
  14. bootup();
  15.  
  16. }
  17.  
  18. void loop() {
  19. // put your main code here, to run repeatedly:
  20. if (!digitalRead(mains) && digitalRead(powerswitch) && analogRead(voltagepin)<402 ){
  21. digitalWrite(shutmedown,HIGH);
  22. delay(25000);
  23. digitalWrite(powerswitch,LOW);
  24. digitalWrite(shutmedown,LOW);
  25. delay(5000);
  26. }
  27.  
  28. if(!digitalRead(powerswitch) && analogRead(voltagepin)>400 && digitalRead(mains)){
  29. digitalWrite(powerswitch,HIGH);
  30. }
  31.  
  32. delay(10);
  33.  
  34. }
  35.  
  36. void bootup()
  37. {
  38. bool flag = false;
  39.  
  40. while( flag == false ) //while charging lock in loop till voltage is above ref and mains is on
  41.  
  42. {
  43. flag = digitalRead(mains) && analogRead(voltagepin)>400;
  44. //Karl Agius was here ^^^^^^^^^
  45. delay(500);//little wait
  46. }
  47. //Once Flag true Power On
  48. digitalWrite(powerswitch,HIGH);
  49. delay(10000); //bootup time
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement