Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. #include"rgb_lcd.h"
  2.  
  3. struct
  4. {
  5. int okres;
  6. int czas_ostatniej_zmiany;
  7. int stan;
  8. int ilepowtorzen;
  9. } dioda, buzzer;
  10.  
  11. struct
  12. {
  13. int odwiezanie = 1000;
  14. int czas_ostatniej_zmiany;
  15. } temperatura;
  16.  
  17. int ledPin = 5;
  18. int temperaturePin = 8;
  19. int servoPin = 4;
  20. int buzzerPin = 2;
  21. rgb_lcd lcd;
  22. int red = 255;
  23. int green = 0;
  24. int blue = 0;
  25.  
  26. String herceiczas;
  27. int czestotliwoscint;
  28.  
  29. void setup() {
  30. // put your setup code here, to run once:
  31. pinMode(ledPin, OUTPUT);
  32. pinMode(buzzerPin, OUTPUT);
  33. lcd.begin(16, 2);
  34. lcd.display();
  35. buzzer.okres = 500;
  36. lcd.setRGB(red, green, blue);
  37.  
  38.  
  39. dioda.okres = 0;
  40. dioda.stan = LOW;
  41. dioda.czas_ostatniej_zmiany = millis();
  42. Serial.begin(9600);
  43.  
  44. lcd.print("eluwina");
  45. Serial.println("Witaj ziemski bycie, jestem arduino i niezle mnie pokrecilo!");
  46. }
  47.  
  48. int obsluga_diody()
  49. {
  50. int uplynelo = millis() - dioda.czas_ostatniej_zmiany;
  51. if (dioda.stan == LOW && uplynelo >= dioda.okres)
  52. {
  53. dioda.stan = HIGH;
  54. dioda.czas_ostatniej_zmiany = millis();
  55. digitalWrite(ledPin, dioda.stan);
  56. }
  57. else
  58. if (dioda.stan == HIGH && uplynelo >= dioda.okres)
  59. {
  60. dioda.stan = LOW;
  61. dioda.czas_ostatniej_zmiany = millis();
  62. digitalWrite(ledPin, dioda.stan);
  63. }
  64. }
  65.  
  66. void obsluga_temperatury_C(String konsola)
  67. {
  68. int reading = analogRead(temperaturePin);
  69. float voltage = reading * 5.0;
  70. voltage /= 1024.0;
  71.  
  72. Serial.print(voltage); Serial.println(" volts");
  73. float stopnieC = (voltage - 1.6) * 100 ;
  74. float stopnieK = stopnieC + 273.15;
  75. if(konsola.endsWith("C")
  76. {
  77. Serial.print(stopnieC); Serial.println(" temperatura [C]");
  78. lcd.setCursor(0, 1);
  79. lcd.print(stopnieC); Serial.println(" temperatura [C]");
  80. }
  81. if(konsola.endsWith("K"))
  82. {
  83. Serial.print(stopnieK); Serial.println(" temperatura [K]");
  84. lcd.setCursor(0, 1);
  85. lcd.print(stopnieC); Serial.println(" temperatura [K]");
  86. }
  87. }
  88. }
  89.  
  90. void obsluga_tekstulcd()
  91. {
  92. if(Serial.available()){
  93. String inttxt = Serial.readString();
  94. if (inttxt){
  95. lcd.setCursor(1, 0);
  96. lcd.clear();
  97. Serial.print(inttxt);
  98. lcd.print(inttxt);
  99. }
  100. }
  101. }
  102.  
  103. void obsluga_buzzera(String konsola)
  104. {
  105. String herceiczas = konsola.substring(5);
  106. int czestotliwoscint = herceiczas.toInt();
  107. Serial.print(czestotliwoscint);
  108. tone(buzzerPin, czestotliwoscint);
  109. }
  110.  
  111. void obsluga_buzzera_razy(String konsola)
  112. {
  113. int uplynelo = millis() - buzzer.czas_ostatniej_zmiany;
  114. if (uplynelo >= buzzer.okres){
  115. Serial.print(czestotliwoscint);
  116. tone(buzzerPin, czestotliwoscint, 500);
  117. buzzer.czas_ostatniej_zmiany = millis();
  118. Serial.println(buzzer.okres);
  119. --buzzer.ilepowtorzen;
  120. }
  121. }
  122.  
  123.  
  124. int obsluga_konsoli(String konsola)
  125. {
  126. if(konsola.startsWith("temp ")){
  127. obsluga_temperatury(konsola);
  128. }
  129.  
  130. if(konsola.startsWith("dioda ")){
  131. String hz = konsola.substring(6);
  132. dioda.okres =500/hz.toFloat();
  133. Serial.println(dioda.okres);
  134. }
  135.  
  136.  
  137. if(konsola.startsWith("dioda stop")){
  138. dioda.stan = LOW;
  139. dioda.okres = 0;
  140. }
  141.  
  142. if(konsola.startsWith("lcd ")){
  143. lcd.clear();
  144. Serial.print(konsola.substring(4));
  145. lcd.print(konsola.substring(4));
  146. }
  147.  
  148. if(konsola.startsWith("buzz ")){
  149. if(konsola.indexOf("razy")!=-1){
  150. int posrazy = konsola.indexOf("razy"); //na ktorym miejscu rozpoczyna sie w stringu slowo "razy"
  151. herceiczas = konsola.substring(5);
  152. czestotliwoscint = herceiczas.toInt();
  153. buzzer.ilepowtorzen = konsola.substring(posrazy+4).toInt();
  154. Serial.println(buzzer.ilepowtorzen);
  155.  
  156. if(konsola.indexOf("pauza")!=-1){
  157. int pospauza = konsola.indexOf("pauza");
  158. buzzer.okres = konsola.substring(pospauza+5).toInt();
  159. }
  160. }
  161. else
  162. herceiczas = konsola.substring(5);
  163. czestotliwoscint = herceiczas.toInt();
  164. obsluga_buzzera(konsola);
  165. }
  166.  
  167. if(konsola.startsWith("buzz stop"))
  168. noTone(buzzerPin);
  169.  
  170. if(konsola.startsWith("info")){
  171. Serial.print("(C) 2020 Majkel Dzordan /n");
  172. }
  173. }
  174.  
  175. void loop() {
  176. // put your main code here, to run repeatedly:
  177. String konsola = Serial.readString();
  178. if(konsola)
  179. obsluga_konsoli(konsola);
  180.  
  181. if(dioda.okres != 0)
  182. obsluga_diody();
  183.  
  184. if(buzzer.ilepowtorzen != 0){
  185. obsluga_buzzera_razy(konsola);
  186. Serial.println(buzzer.ilepowtorzen);
  187. }
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement