Advertisement
Guest User

Untitled

a guest
Jan 28th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. /*********************************************************************
  2. gnd vcc clk mosi rst dc
  3. *********************************************************************/
  4. #include "pitches.h"
  5. #include <SPI.h>
  6. #include <Wire.h>
  7. #include <Adafruit_GFX.h>
  8. #include <Adafruit_SSD1306.h>
  9. #define SSD1306_128_64
  10.  
  11. #define OLED_MOSI 5
  12. #define OLED_CLK 4
  13. #define OLED_DC 7
  14. #define OLED_CS 12
  15. #define OLED_RESET 6
  16. Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  17.  
  18. long settime = 240;
  19. long disptime;
  20. long end_time;
  21. long disptimeM;
  22. long disptimeS;
  23. boolean start = false;
  24.  
  25. unsigned long currentTime;
  26. unsigned long loopTime;
  27. const int pin_A = 8;
  28. const int pin_B = 9;
  29. unsigned char encoder_A;
  30. unsigned char encoder_B;
  31. unsigned char encoder_A_prev = 0;
  32. int fadeAmount = 10;
  33.  
  34. int noteDurations[] = {
  35. 4, 8, 8, 4, 4, 4, 4, 4
  36. };
  37. int melody[] = {
  38. NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
  39. };
  40.  
  41.  
  42. void knopka()
  43. {
  44. static unsigned long millis_prev;
  45. if (millis() - 300 > millis_prev)
  46. start = !start; // меняем значение на противоположное
  47. millis_prev = millis();
  48. }
  49.  
  50. void setup() {
  51. pinMode (4, INPUT);
  52. display.begin(32);
  53. display.clearDisplay();
  54. pinMode (11, OUTPUT);
  55. digitalWrite(11, HIGH);
  56. attachInterrupt(0, knopka, RISING);
  57.  
  58. pinMode(pin_A, INPUT);
  59. pinMode(pin_B, INPUT);
  60. currentTime = millis();
  61. loopTime = currentTime;
  62.  
  63. display.clearDisplay();
  64. display.setTextSize(1);
  65. display.setTextColor(WHITE);
  66. display.setCursor(0, 0);
  67. display.println("VNIMANIE!");
  68.  
  69. display.setTextSize(1);
  70. display.setTextColor(WHITE);
  71. display.setCursor(0, 8);
  72. display.println("Ultrafiolet vredit ");
  73.  
  74. display.setTextSize(1);
  75. display.setTextColor(WHITE);
  76. display.setCursor(0, 16);
  77. display.println("glazam i kozhe.");
  78.  
  79. display.setTextSize(1);
  80. display.setTextColor(WHITE);
  81. display.setCursor(0, 24);
  82. display.println("Ispolzovat razumno.");
  83. display.display();
  84. for (int thisNote = 0; thisNote < 8; thisNote++) {
  85. int noteDuration = 1000 / noteDurations[thisNote];
  86. tone(10, melody[thisNote], noteDuration);
  87. int pauseBetweenNotes = noteDuration * 1.30;
  88. delay(pauseBetweenNotes);
  89. noTone(10);
  90. }
  91. delay(3000);
  92.  
  93.  
  94.  
  95. }
  96.  
  97.  
  98.  
  99. void schet ()
  100. {
  101. tone(10, 1000, 250);
  102. disptime = settime;
  103. end_time = millis() + (disptime * 1000);
  104.  
  105. while (disptime > 0 ) {
  106.  
  107.  
  108.  
  109.  
  110. disptime = (end_time - millis()) / 1000;
  111. disptimeM = disptime / 60;
  112. disptimeS = disptime - (disptimeM * 60);
  113.  
  114.  
  115.  
  116.  
  117.  
  118. display.clearDisplay();
  119. display.setTextSize(1);
  120. display.setTextColor(WHITE);
  121. display.setCursor(0, 0);
  122. display.println("OCTATOK:");
  123. display.setTextSize(3);
  124. display.setTextColor(WHITE);
  125. display.setCursor(25, 8);
  126. if (disptimeM > 0)
  127. {
  128. display.println(disptimeM);
  129. display.setTextSize(2);
  130. display.setCursor(44, 15);
  131. display.println("M");
  132. }
  133. if (disptimeS < 10)
  134. {
  135. display.setTextSize(3);
  136. display.setCursor(65, 8);
  137. display.println("0");
  138. display.setCursor(83, 8);
  139. display.println(disptimeS);
  140. }
  141. else
  142. {
  143. display.setTextSize(3);
  144. display.setCursor(65, 8);
  145. display.println(disptimeS);
  146. }
  147. display.setTextSize(2);
  148. display.setCursor(103, 15);
  149. display.println("C");
  150. display.display();
  151.  
  152. if (start == false)
  153. {
  154. digitalWrite(11, HIGH);
  155. tone(10, 500, 250);
  156. tone(10, 0, 250);
  157. tone(10, 500, 250);
  158. break;
  159. }
  160.  
  161. }
  162. digitalWrite(11, HIGH);
  163. tone(10, 500, 200);
  164. delay(400);
  165. tone(10, 500, 300);
  166. start = false;
  167. }
  168.  
  169.  
  170.  
  171.  
  172.  
  173. void loop() {
  174. currentTime = millis();
  175. if (currentTime >= (loopTime + 1)) {
  176. encoder_A = digitalRead(pin_A);
  177. encoder_B = digitalRead(pin_B);
  178. if ((!encoder_A) && (encoder_A_prev)) {
  179. if (encoder_B) {
  180. if (settime + fadeAmount <= 599) settime += fadeAmount;
  181. }
  182. else {
  183. if (settime - fadeAmount >= 0) settime -= fadeAmount;
  184. }
  185. }
  186. encoder_A_prev = encoder_A;
  187. loopTime = currentTime;
  188. }
  189. if (start == true)
  190. {
  191. digitalWrite(11, LOW);
  192. schet();
  193. }
  194. display.clearDisplay();
  195. disptime = settime;
  196. disptimeM = disptime / 60;
  197. disptimeS = disptime - (disptimeM * 60);
  198. display.setTextSize(1);
  199. display.setTextColor(WHITE);
  200. display.setCursor(0, 0);
  201. display.println("HACTPOuKA:");
  202. // display.drawPixel(39, 0, WHITE);
  203. //display.drawPixel(37, 0, WHITE);
  204. display.drawPixel(38, 0, WHITE);
  205. display.setTextSize(3);
  206. display.setTextColor(WHITE);
  207. display.setCursor(25, 8);
  208. if (disptimeM > 0)
  209. {
  210. display.println(disptimeM);
  211. display.setTextSize(2);
  212. display.setCursor(44, 15);
  213. display.println("M");
  214. }
  215. if (disptimeS < 10)
  216. {
  217. display.setTextSize(3);
  218. display.setCursor(65, 8);
  219. display.println("0");
  220. display.setCursor(83, 8);
  221. display.println(disptimeS);
  222. }
  223. else
  224. {
  225. display.setTextSize(3);
  226. display.setCursor(65, 8);
  227. display.println(disptimeS);
  228. }
  229. display.setTextSize(2);
  230. display.setCursor(103, 15);
  231. display.println("C");
  232. display.display();
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement