Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"rgb_lcd.h"
- struct
- {
- int okres;
- int czas_ostatniej_zmiany;
- int stan;
- int ilepowtorzen;
- } dioda, buzzer;
- struct
- {
- int odwiezanie = 1000;
- int czas_ostatniej_zmiany;
- } temperatura;
- int ledPin = 5;
- int temperaturePin = 8;
- int servoPin = 4;
- int buzzerPin = 2;
- rgb_lcd lcd;
- int red = 255;
- int green = 0;
- int blue = 0;
- String herceiczas;
- int czestotliwoscint;
- void setup() {
- // put your setup code here, to run once:
- pinMode(ledPin, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- lcd.begin(16, 2);
- lcd.display();
- buzzer.okres = 500;
- lcd.setRGB(red, green, blue);
- dioda.okres = 0;
- dioda.stan = LOW;
- dioda.czas_ostatniej_zmiany = millis();
- Serial.begin(9600);
- lcd.print("eluwina");
- Serial.println("Witaj ziemski bycie, jestem arduino i niezle mnie pokrecilo!");
- }
- int obsluga_diody()
- {
- int uplynelo = millis() - dioda.czas_ostatniej_zmiany;
- if (dioda.stan == LOW && uplynelo >= dioda.okres)
- {
- dioda.stan = HIGH;
- dioda.czas_ostatniej_zmiany = millis();
- digitalWrite(ledPin, dioda.stan);
- }
- else
- if (dioda.stan == HIGH && uplynelo >= dioda.okres)
- {
- dioda.stan = LOW;
- dioda.czas_ostatniej_zmiany = millis();
- digitalWrite(ledPin, dioda.stan);
- }
- }
- void obsluga_temperatury_C(String konsola)
- {
- int reading = analogRead(temperaturePin);
- float voltage = reading * 5.0;
- voltage /= 1024.0;
- Serial.print(voltage); Serial.println(" volts");
- float stopnieC = (voltage - 1.6) * 100 ;
- float stopnieK = stopnieC + 273.15;
- if(konsola.endsWith("C")
- {
- Serial.print(stopnieC); Serial.println(" temperatura [C]");
- lcd.setCursor(0, 1);
- lcd.print(stopnieC); Serial.println(" temperatura [C]");
- }
- if(konsola.endsWith("K"))
- {
- Serial.print(stopnieK); Serial.println(" temperatura [K]");
- lcd.setCursor(0, 1);
- lcd.print(stopnieC); Serial.println(" temperatura [K]");
- }
- }
- }
- void obsluga_tekstulcd()
- {
- if(Serial.available()){
- String inttxt = Serial.readString();
- if (inttxt){
- lcd.setCursor(1, 0);
- lcd.clear();
- Serial.print(inttxt);
- lcd.print(inttxt);
- }
- }
- }
- void obsluga_buzzera(String konsola)
- {
- String herceiczas = konsola.substring(5);
- int czestotliwoscint = herceiczas.toInt();
- Serial.print(czestotliwoscint);
- tone(buzzerPin, czestotliwoscint);
- }
- void obsluga_buzzera_razy(String konsola)
- {
- int uplynelo = millis() - buzzer.czas_ostatniej_zmiany;
- if (uplynelo >= buzzer.okres){
- Serial.print(czestotliwoscint);
- tone(buzzerPin, czestotliwoscint, 500);
- buzzer.czas_ostatniej_zmiany = millis();
- Serial.println(buzzer.okres);
- --buzzer.ilepowtorzen;
- }
- }
- int obsluga_konsoli(String konsola)
- {
- if(konsola.startsWith("temp ")){
- obsluga_temperatury(konsola);
- }
- if(konsola.startsWith("dioda ")){
- String hz = konsola.substring(6);
- dioda.okres =500/hz.toFloat();
- Serial.println(dioda.okres);
- }
- if(konsola.startsWith("dioda stop")){
- dioda.stan = LOW;
- dioda.okres = 0;
- }
- if(konsola.startsWith("lcd ")){
- lcd.clear();
- Serial.print(konsola.substring(4));
- lcd.print(konsola.substring(4));
- }
- if(konsola.startsWith("buzz ")){
- if(konsola.indexOf("razy")!=-1){
- int posrazy = konsola.indexOf("razy"); //na ktorym miejscu rozpoczyna sie w stringu slowo "razy"
- herceiczas = konsola.substring(5);
- czestotliwoscint = herceiczas.toInt();
- buzzer.ilepowtorzen = konsola.substring(posrazy+4).toInt();
- Serial.println(buzzer.ilepowtorzen);
- if(konsola.indexOf("pauza")!=-1){
- int pospauza = konsola.indexOf("pauza");
- buzzer.okres = konsola.substring(pospauza+5).toInt();
- }
- }
- else
- herceiczas = konsola.substring(5);
- czestotliwoscint = herceiczas.toInt();
- obsluga_buzzera(konsola);
- }
- if(konsola.startsWith("buzz stop"))
- noTone(buzzerPin);
- if(konsola.startsWith("info")){
- Serial.print("(C) 2020 Majkel Dzordan /n");
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- String konsola = Serial.readString();
- if(konsola)
- obsluga_konsoli(konsola);
- if(dioda.okres != 0)
- obsluga_diody();
- if(buzzer.ilepowtorzen != 0){
- obsluga_buzzera_razy(konsola);
- Serial.println(buzzer.ilepowtorzen);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement