Advertisement
Guest User

arduino

a guest
Jul 26th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.42 KB | None | 0 0
  1.  
  2. // when compiling for attiny erase serial print and change pin numbers
  3.  
  4.  
  5.  
  6. // relay pin
  7.  
  8. #define relay_PIN0 0 // 0
  9. #define relay_PIN1 0
  10. #define relay_PIN2 0
  11. #define relay_PIN3 0
  12. #define relay_PIN4 0
  13. #define relay_PIN5 0
  14.  
  15. // for counting
  16.  
  17. int increasetempbutton = 3; // switch is connected to pin 4
  18. int va;// variable for reading the pin status
  19. int buttonState2; // variable to hold the button state
  20. int buttonPresses = 0; // how many times the button has been pressed
  21. int count;
  22.  
  23. int decreasetempbutton = 2; // switch is connected to pin 4
  24. int buttonState3;
  25. int va2;// variable for reading the pin status
  26.  
  27.  
  28. //button to make count go to zero
  29.  
  30. int button = 5; // the number of the pushbutton pin
  31. int buttonState = 0; // variable for reading the pushbutton status
  32.  
  33.  
  34.  
  35.  
  36. // debouce
  37.  
  38.  
  39. long lastDebounceTime = 0; // the last time the output pin was toggled
  40. long debounceDelay = 50; // the debounce time; increase if the output flickers
  41.  
  42. // for the timing on and off
  43.  
  44. #define relay_ON1 1000 //milliseconds
  45. #define relay_OFF1 10000
  46.  
  47. #define relay_ON2 1000 //milliseconds
  48. #define relay_OFF2 5000
  49.  
  50. #define relay_ON3 2000 //milliseconds
  51. #define relay_OFF3 3000
  52.  
  53. #define relay_ON4 2000 //milliseconds
  54. #define relay_OFF4 2000
  55.  
  56. unsigned long ms1; //time from millis()
  57. unsigned long msLast1; //last time the LED changed state
  58.  
  59. unsigned long ms2; //time from millis()
  60. unsigned long msLast2; //last time the LED changed state
  61.  
  62. unsigned long ms3; //time from millis()
  63. unsigned long msLast3; //last time the LED changed state
  64.  
  65. unsigned long ms4; //time from millis()
  66. unsigned long msLast4; //last time the LED changed state
  67.  
  68.  
  69.  
  70. boolean relayState1; //current LED state
  71. boolean relayState2; //current LED state
  72. boolean relayState3;
  73. boolean relayState4; //current LED state
  74.  
  75.  
  76. boolean replay0 = true; // to blink once
  77. boolean replay1 = true; // to blink once
  78. boolean replay2 = true; // to blink once
  79. boolean replay3 = true; // to blink once
  80. boolean replay4 = true; // to blink once
  81. boolean replay5 = true; // to blink once
  82.  
  83.  
  84. void setup(void)
  85. {
  86. pinMode(relay_PIN0, OUTPUT);
  87. pinMode(relay_PIN1, OUTPUT);
  88. pinMode(relay_PIN2, OUTPUT);
  89. pinMode(relay_PIN3, OUTPUT);
  90. pinMode(relay_PIN4, OUTPUT);
  91. pinMode(relay_PIN5, OUTPUT);
  92. pinMode(4, OUTPUT);
  93. pinMode(13, OUTPUT);
  94. pinMode(button, INPUT);
  95. pinMode(increasetempbutton, INPUT);
  96. pinMode(decreasetempbutton, INPUT);
  97. buttonState2 = digitalRead(increasetempbutton); // read the initial state
  98. buttonState3 = digitalRead(decreasetempbutton);
  99. buttonState = digitalRead(button);
  100. Serial.begin(9600);
  101. }
  102.  
  103. void loop(void)
  104. {
  105.  
  106.  
  107. if (buttonState == HIGH) {
  108.  
  109.  
  110.  
  111. digitalWrite(13, HIGH);
  112.  
  113. }
  114.  
  115. buttonState2 = va;
  116. buttonState3 = va2;
  117. count = buttonPresses;
  118. Serial.println(count);
  119. ms1 = millis();
  120. ms2 = millis();
  121. ms3 = millis();
  122. ms4 = millis();
  123.  
  124. va = digitalRead(increasetempbutton);
  125. if (va != buttonState2) {
  126. if (va == LOW) {
  127. buttonPresses++ ;
  128. }
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135. va2 = digitalRead(decreasetempbutton);
  136. if (va2 != buttonState3) {
  137. if (va2 == LOW) {
  138. buttonPresses-- ;
  139. }
  140.  
  141. }
  142.  
  143.  
  144.  
  145.  
  146.  
  147. //blink code and count this make the count go to 0 again
  148.  
  149. if (count > 5) {
  150.  
  151. buttonPresses--;
  152. buttonPresses--;
  153. buttonPresses--;
  154. buttonPresses--;
  155. buttonPresses--;
  156. buttonPresses--;
  157. }
  158.  
  159. if (count < 0 ) {
  160.  
  161. buttonPresses++;
  162. buttonPresses++;
  163. buttonPresses++;
  164. buttonPresses++;
  165. buttonPresses++;
  166. buttonPresses++;
  167. }
  168.  
  169.  
  170.  
  171.  
  172.  
  173. if (count == 0) {
  174.  
  175. digitalWrite(relay_PIN0, LOW);
  176. if (replay0 == true) {
  177.  
  178. replay0 = false;
  179. replay1 = true;
  180. replay5 = true;
  181. }
  182. }
  183.  
  184. if (count == 1) {
  185.  
  186.  
  187. if (ms1 - msLast1 > (relayState1 ? relay_ON1 : relay_OFF1)) {
  188. digitalWrite(relay_PIN1, relayState1 = !relayState1);
  189. msLast1 = ms1; }
  190.  
  191. if (replay1 == true) {
  192.  
  193. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  194. delay(150); // wait for a second
  195. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  196. delay(150);
  197. replay1 = false;
  198.  
  199. }
  200. replay2 = true;
  201. replay0 = true;
  202. }
  203.  
  204.  
  205.  
  206.  
  207. if (count == 2) {
  208. if (ms2 - msLast2 > (relayState2 ? relay_ON2 : relay_OFF2)) {
  209. digitalWrite(relay_PIN2, relayState2 = !relayState2);
  210. msLast2 = ms2; }
  211.  
  212. if(replay2 == true){
  213.  
  214. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  215. delay(150); // wait for a second
  216. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  217. delay(150);
  218. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  219. delay(150); // wait for a second
  220. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  221. delay(150);
  222. replay2 = false;
  223. }
  224. replay1 = true;
  225. replay3 = true;
  226. }
  227.  
  228.  
  229.  
  230. if (count == 3) {
  231. if (ms3 - msLast3 > (relayState3 ? relay_ON3 : relay_OFF3)) {
  232. digitalWrite(relay_PIN3, relayState3 = !relayState3);
  233. msLast3 = ms3;
  234. }
  235. if(replay3 == true){
  236.  
  237. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  238. delay(150); // wait for a second
  239. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  240. delay(150);
  241. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  242. delay(150); // wait for a second
  243. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  244. delay(150);
  245. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  246. delay(150); // wait for a second
  247. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  248. delay(150);
  249. replay3 = false;
  250. }
  251. replay2 = true;
  252. replay4 = true;
  253. }
  254.  
  255.  
  256. if (count == 4) {
  257. if (ms4 - msLast4 > (relayState4 ? relay_ON4 : relay_OFF4)) {
  258. digitalWrite(relay_PIN4, relayState4 = !relayState4);
  259. msLast4 = ms4;
  260. }
  261. if (replay4 == true)
  262. {
  263. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  264. delay(250); // wait for a second
  265. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  266. delay(250);
  267. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  268. delay(250); // wait for a second
  269. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  270. delay(250);
  271. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  272. delay(250); // wait for a second
  273. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  274. delay(250);
  275. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  276. delay(250); // wait for a second
  277. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  278. delay(250);
  279.  
  280. replay4 = false;
  281. }
  282. replay3 = true;
  283. replay5 = true;
  284. }
  285.  
  286. if (count == 5) {
  287.  
  288. digitalWrite(relay_PIN0, LOW);
  289.  
  290. if(replay5 == true){
  291. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  292. delay(250); // wait for a second
  293. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  294. delay(250);
  295. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  296. delay(250); // wait for a second
  297. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  298. delay(250);
  299. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  300. delay(250); // wait for a second
  301. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  302. delay(250);
  303. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  304. delay(250); // wait for a second
  305. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  306. delay(250);
  307. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
  308. delay(250); // wait for a second
  309. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
  310. delay(250);
  311. replay5 = false;
  312. }
  313. replay4 = true;
  314. replay0 = true;
  315. }
  316.  
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement