This shows you the differences between two versions of the page.
pm:prj2023:alexau:smart-temperature-alarm [2023/05/27 11:55] andrei_stefan.fotin [Software Design] |
pm:prj2023:alexau:smart-temperature-alarm [2023/05/27 12:04] (current) andrei_stefan.fotin [Software Design] |
||
---|---|---|---|
Line 37: | Line 37: | ||
<note tip> | <note tip> | ||
- | Descrierea software a aplicaţiei: | ||
- | |||
Aplicatia utilizeaza 2 Arduino Uno, care comunica prin I2C. | Aplicatia utilizeaza 2 Arduino Uno, care comunica prin I2C. | ||
Fiecare are rolul sau: | Fiecare are rolul sau: | ||
- | * Slave-ul primeste temperatura de la Master si o afiseaza pe LCD. | + | * Slave-ul primeste temperatura de la Master si o afiseaza pe LCD. |
- | * Master-ul reprezinta efectiv alarma de temperatura. | + | * Master-ul reprezinta efectiv alarma de temperatura. |
+ | |||
+ | Mediu de dezvoltare: | ||
+ | * Arduino IDE | ||
+ | * Tinkercad | ||
</note> | </note> | ||
- | <note tip> | + | ===== Source Code & Documentation ===== |
- | Slave Source Code | + | https://github.com/StefanFotin23/Smart-Temperature-Alarm-Arduino |
- | + | ||
- | /** SLAVE **/ | + | |
- | #include <LiquidCrystal.h> | + | |
- | #include <Wire.h> | + | |
- | + | ||
- | // The slave address to which this master will send data | + | |
- | #define I2C_SLAVE_ADDRESS 0x09 | + | |
- | + | ||
- | // The byte variable in which I2C reads from the master are performed | + | |
- | int i; | + | |
- | signed int aux; | + | |
- | int temp; | + | |
- | const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; | + | |
- | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | + | |
- | + | ||
- | void setup() { | + | |
- | lcd.begin(16, 2); | + | |
- | lcd.print("Buna ziua!"); | + | |
- | Wire.begin(I2C_SLAVE_ADDRESS); | + | |
- | } | + | |
- | + | ||
- | void receiveEvent(int numBytes) { | + | |
- | i = 3; | + | |
- | temp = 0; | + | |
- | while (0 <= i) { | + | |
- | aux = Wire.read(); | + | |
- | if (aux > 127) { | + | |
- | aux = aux - 256; | + | |
- | } | + | |
- | temp = temp + pow(10, i) * aux; | + | |
- | i--; | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | void loop() { | + | |
- | Wire.onReceive(receiveEvent); | + | |
- | if (temp != 0) { | + | |
- | lcd.clear(); | + | |
- | lcd.print("Temp refresh"); | + | |
- | delay(500); | + | |
- | lcd.clear(); | + | |
- | lcd.print(temp / 100); | + | |
- | lcd.print("."); | + | |
- | lcd.print(abs(temp % 100)); | + | |
- | lcd.print(" grade C"); | + | |
- | delay(5000); | + | |
- | } | + | |
- | } | + | |
- | </note> | + | |