Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* the master read temp,desirable temp and damper status from the slave
- * turn on/off damper status from the slave.
- * view on TFT (serial monitor) the temp,desirable temp and damper status
- * room[x].room_temperature
- * room[x].user_temperature
- * room[x].motor_damper_status
- * room[x].thermostat_power_status
- * x - number of room
- */
- #include <TFT_ILI9341.h>
- #include <SPI.h>
- #define TFT_GREY 0x5AEB
- TFT_ILI9341 tft = TFT_ILI9341(); // Invoke custom library
- #include "thermostat.h" /* include class for each room thermostat
- thermostat room[4]; /* define 5 room thermostat from [0] to [4], customize class in thermostat.h
- // convert room number to words for facilities
- #define one 0
- #define two 1
- #define three 2
- #define four 3
- #define five 4
- /* define I2C port for each room thermostat
- each one is a standalone ATMEGA328P connected by I2C
- #define room1 2
- #define room2 3
- #define room3 4
- #define room4 5
- #define room5 6
- #include "Wire.h"
- #include <AnalogMatrixKeypad.h> // keypad library
- #define analogPin 0 // keypad read,input pin
- AnalogMatrixKeypad AnMatrixKeypad(analogPin); //define the keypad
- #include "dampermotor.h" // add custom library to open or close room damper
- #define motor_timeout 1500 // timeout for turning on or off the damper room for 3 sec
- // define motor pins to driving for each rooms with the timeout
- dampermotor motor_room1(2,3,motor_timeout);
- dampermotor motor_room2(4,5,motor_timeout);
- dampermotor motor_room3(6,7,motor_timeout);
- dampermotor motor_room4(8,9,motor_timeout);
- dampermotor motor_room5(10,11,motor_timeout);
- dampermotor motor_bypass(12,13,motor_timeout);
- #include "new_RTC.h" //add RTC code to display on the TFT
- #include "check_keypad1.h" //add keypad code to check keypad choice with switch,case
- #include "open_close_room_damper_by_temp1.h" //add damper code to open or close room's damper by room temperature
- // define pins for TFT screen
- #define sclk 52 // Don't change
- #define mosi 51 // Don't change
- #define miso 50
- #define cs 9
- #define dc 8
- #define rst 7 // you can also connect this to the Arduino reset
- // read from keypad
- void presskeypad()
- {
- Key = AnMatrixKeypad.readKey();
- if(Key != KEY_NOT_PRESSED)
- {
- Serial.println(Key); // send pressed key to serial monitor
- }
- }
- // Master write to Slave, send data to Slave
- void write_to_slave(int slave_number, int desirable_temp, boolean mode)
- {
- Wire.beginTransmission(slave_number); // start data transmission to device #slave_number
- Wire.write(desirable_temp); // send one byte
- Wire.write(mode); // send one byte
- Wire.endTransmission(); // stop transmitting
- }
- // Master reade form Slave device <number>, from room[number][i]
- void reader_form_slave(int device,int room_number)
- {
- Wire.requestFrom(device,4); //request 4 bytes from device <number>
- while(Wire.available()) // slave may send less than requested
- {
- for(int i=0;i<4;i++)
- {
- int t;
- t = Wire.read(); // receive a byte as character
- room[room_number].room_temperature=t;
- t = Wire.read();
- room[room_number].user_temperature=t;
- t = Wire.read();
- room[room_number].motor_damper_status=t;
- t = Wire.read();
- room[room_number].thermostat_power_status=t;
- }
- }
- }
- // Delay for 5min.
- void standby()
- {
- while(end_mode_timer - start_mode_timer <= 1000) // 300000 millis for 5min standby before changing mode
- {
- end_mode_timer=millis();
- }
- }
- void setup()
- {
- Wire.begin();
- Serial.begin(9600);
- // start the TFT screen
- tft.init();
- tft.setRotation(3);
- tft.fillScreen(TFT_BLACK);
- }
- void loop()
- {
- //motor_room1.damper_motor_driver();
- //motor_room2.damper_motor_driver();
- //motor_room3.damper_motor_driver();
- //motor_room4.damper_motor_driver();
- //motor_room5.damper_motor_driver();
- //motor_bypass.damper_motor_driver();
- //reader_form_slave(room1,one); //receive data from room1
- //reader_form_slave(room2,two); //receive data from room2
- //reader_form_slave(room3,three); //receive data from room3
- //reader_form_slave(room4,four); //receive data from device room4
- //reader_form_slave(room5,five); //receive data from device room5
- presskeypad(); //read from keypad
- checkeypad(); // check the key pressed and do something
- displayTime(); //read and display from RTC
- //open_close_room_damper_by_temp(); // open or close room's damper by room's thermostat temperature
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement