Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Project: DIY Thermocyler V2.0 Arduino
- // Creator: Tobias and Torben
- // Date of Creation: 10.12.16
- #include "Nextion.h"
- #include <SoftwareSerial.h>
- #include <Wire.h>
- SoftwareSerial HMISerial(10,11); //RX,TX
- //SoftwareSerial ardserial(4,5); //RX,TX
- int cycle = 0;
- int repe = 0;
- int cycle_help = 0;
- int cycle_help_temp = 0;
- int cycle_temp[10];
- int cycle_time[10];
- //----------------------------------------------------------------------------------------------------------------------
- //Nextions Display Buttons
- //Home Screen
- NexButton start = NexButton(0,1,"start");
- NexButton c_time = NexButton(0,3,"C_time");
- NexButton c_temp = NexButton(0,4,"b3");
- //Nextion Test Mode Buttons
- NexButton heat = NexButton(1,1,"heat");
- NexButton cool = NexButton(1,2,"cool");
- NexSlider pwm_heat = NexSlider(1,6,"pwm_heat");
- NexSlider pwm_fan = NexSlider(1,5,"pwm_fan");
- //Nextion Cycle Buttons/Nummber
- NexButton check = NexButton(2,12,"check");
- NexNumber n_cycle = NexNumber(2,16,"n_cycle");
- //Nextion Repetion Buttons/Nummber
- NexButton check_rep = NexButton(5,6,"check");
- NexNumber n_cycle_rep = NexNumber(5,5,"n_cycle");
- //Nextion Cycle Time Buttons/Nummber
- NexButton check_t = NexButton(3,10,"check");
- NexButton next_t = NexButton(3,6,"b13");
- NexButton back_t = NexButton(3,5,"b12");
- NexNumber n_cycle_t = NexNumber(3,2,"n_cycle");
- NexNumber n_cycle_c = NexNumber(3,7,"n0");
- //Nextion Cycle Temp Buttons/Nummber
- NexButton check_temp = NexButton(4,10,"b11");
- NexButton next_temp = NexButton(4,6,"b13");
- NexButton back_temp = NexButton(4,5,"b12");
- NexNumber n_cycle_temp = NexNumber(4,2,"n_cycle");
- NexNumber n_cycle_c_temp = NexNumber(4,7,"n0");
- //----------------------------------------------------------------------------------------------------------------------
- char buffer[100] = {0};
- //Button Press abfrage
- NexTouch *nex_listen_list[] = {
- &heat,
- &cool,
- &pwm_heat,
- &pwm_fan,
- &check,
- &check_rep,
- &check_t,
- &next_t,
- &back_t,
- &start,
- &c_time,
- &check_temp,
- &next_temp,
- &back_temp,
- &c_temp,
- NULL
- };
- //----------------------------------------------------------------------------------------------------------------------
- //Arduino Inilisation
- void setup() {
- Wire.begin(55);
- nexInit();
- Serial.begin(38400);
- //ardserial.begin();
- while (!Serial){
- }
- Serial.println("USB-to-PC Connection etablished");
- //----------------------------------------------------------------------------------------------------------------------
- //Attach Button Funktions
- //Home Screen BUttons
- start.attachPush(start_cycle, &start);
- c_time.attachPush(cycle_time_button,&c_time);
- c_temp.attachPush(cycle_temp_button,&c_temp);
- //Attach Test Mode Buttons
- heat.attachPush(heat_button, &heat);
- cool.attachPush(cool_button, &cool);
- pwm_heat.attachPop(pwm_heat_slider, &pwm_heat);
- pwm_fan.attachPop(pwm_fan_slider, &pwm_fan);
- //Attach Cycle Buttons
- check.attachPush(check_cycle_button, &check);
- //Attach Repetion Buttons
- check_rep.attachPush(check_repe_button,&check_rep);
- //Attach Time Buttons
- check_t.attachPush(check_time_button,&check_t);
- next_t.attachPush(next_t_button,&next_t);
- back_t.attachPush(back_t_button,&back_t);
- //Attach Temperatur Buttons
- check_temp.attachPush(check_temp_button,&check_temp);
- next_temp.attachPush(next_temp_button,&next_temp);
- back_temp.attachPush(back_temp_button,&back_temp);
- //----------------------------------------------------------------------------------------------------------------------
- Serial.println("Setup Complet");
- }
- //Main Loop waiting for actions
- void loop() {
- nexLoop(nex_listen_list);
- }
- //----------------------------------------------------------------------------------------------------------------------
- //start Cycle
- void start_cycle(void *ptr){
- sendData();
- }
- //----------------------------------------------------------------------------------------------------------------------
- //sending data funktio
- void sendData(){
- int temp_ok = 0;
- int time_ok = 0;
- int cycle_ok = 0;
- int i = 0;
- while(!Serial){
- while(cycle_ok == 0){
- Serial.print('S');
- cycle_ok = Serial.read();
- }
- Serial.print(cycle);
- while(temp_ok == 0){
- temp_ok = Serial.read();
- }
- for (byte i = 0; i < (sizeof(cycle_temp)/sizeof(cycle_temp[0])); i++) {
- Serial.print(cycle_temp[i]);
- }
- i = 0;
- while(time_ok == 0){
- time_ok = Serial.read();
- }
- for (byte i = 0; i < (sizeof(cycle_time)/sizeof(cycle_time[0])); i++) {
- Serial.print(cycle_time[i]);
- }
- i = 0;
- delay(100);
- Serial.print("Finished");
- }
- }
- //----------------------------------------------------------------------------------------------------------------------
- //Read Data from Nextion
- //Receving number of cycles
- void check_cycle_button(void *ptr){
- uint32_t cycle_value_value = 0;
- n_cycle.getValue(&cycle_value_value);
- cycle = cycle_value_value;
- }
- //Receving number of Repetions
- void check_repe_button(void *ptr){
- uint32_t repe_value = 0;
- n_cycle_rep.getValue(&repe_value);
- repe = repe_value;
- }
- //Cycle Temperature
- //----------------------------------------------------------
- void cycle_temp_button(void *ptr){
- //This is needed if you leave it and join it again
- n_cycle_temp.setValue(cycle_temp[0]);
- Serial.print("test");
- }
- void check_temp_button(void *ptr){
- for (int h = 0; h < cycle+1;h++){
- Serial.print(cycle_temp[h]);
- }
- }
- //Temp for each Cycle
- void next_temp_button(void *ptr){
- uint32_t cycle_temp_value = 0;
- // cycle = EEPROM.read(200);
- if (cycle_help_temp == cycle){
- n_cycle_temp.getValue(&cycle_temp_value);
- cycle_temp[cycle_help_temp] = cycle_temp_value;
- cycle_help_temp = 0;
- n_cycle_temp.setValue(cycle_time[cycle_help_temp]);
- n_cycle_c_temp.setValue(cycle_help_temp);
- }else {
- n_cycle_temp.getValue(&cycle_temp_value);
- cycle_temp[cycle_help_temp] = cycle_temp_value;
- ++cycle_help_temp;
- n_cycle_c_temp.setValue(cycle_help_temp);
- n_cycle_temp.setValue(cycle_temp[cycle_help_temp]);
- }
- }
- void back_temp_button(void *ptr){
- if (cycle_help_temp == 0){
- cycle_help_temp = cycle;
- n_cycle_temp.setValue(cycle_temp[cycle_help_temp]);
- n_cycle_c_temp.setValue(cycle_help_temp);
- }else {
- --cycle_help_temp;
- n_cycle_temp.setValue(cycle_temp[cycle_help_temp]);
- n_cycle_c_temp.setValue(cycle_help_temp);
- }
- }
- //----------------------------------------------------------
- //Cycle Time
- //Time of each Cycles
- void cycle_time_button(void *ptr){
- //This is needed if you leave it and join it again
- n_cycle_t.setValue(cycle_time[0]);
- Serial.print("test");
- }
- void check_time_button(void *ptr){
- for (int h = 0; h < cycle+1;h++){
- Serial.print(cycle_time[h]);
- }
- }
- //Temp for each Cycle
- void next_t_button(void *ptr){
- uint32_t cycle_t_value = 0;
- // cycle = EEPROM.read(200);
- Serial.print("Ich gehe hier rein");
- if (cycle_help == cycle){
- n_cycle_t.getValue(&cycle_t_value);
- cycle_time[cycle_help] = cycle_t_value;
- cycle_help = 0;
- n_cycle_t.setValue(cycle_time[cycle_help]);
- n_cycle_c.setValue(cycle_help);
- }else {
- n_cycle_t.getValue(&cycle_t_value);
- cycle_time[cycle_help] = cycle_t_value;
- ++cycle_help;
- n_cycle_c.setValue(cycle_help);
- n_cycle_t.setValue(cycle_time[cycle_help]);
- }
- }
- void back_t_button(void *ptr){
- if (cycle_help == 0){
- cycle_help = cycle;
- n_cycle_t.setValue(cycle_time[cycle_help]);
- n_cycle_c.setValue(cycle_help);
- }else {
- --cycle_help;
- n_cycle_t.setValue(cycle_time[cycle_help]);
- n_cycle_c.setValue(cycle_help);
- }
- }
- //----------------------------------------------------------
- //----------------------------------------------------------------------------------------------------------------------
- //Begin Test Mode
- bool stop;void heat_button (void *ptr){
- Wire.beginTransmission(52);
- Wire.write('H');
- Wire.endTransmission();
- Serial.print("Test");
- }
- void cool_button (void *ptr){
- Wire.beginTransmission(52);
- Wire.write('C');
- Wire.endTransmission();
- }
- void pwm_heat_slider (void *ptr){
- uint32_t pwm_heat_value = 0;
- pwm_heat.getValue(&pwm_heat_value);
- Wire.beginTransmission(42);
- Wire.write('V');
- Wire.endTransmission();
- Wire.beginTransmission(42);
- Wire.write(pwm_heat_value);
- Serial.println(pwm_heat_value);
- }
- void pwm_fan_slider (void *ptr){
- uint32_t pwm_fan_value = 0;
- pwm_fan.getValue(&pwm_fan_value);
- Wire.beginTransmission(42);
- Wire.write('F');
- Wire.endTransmission();
- Wire.beginTransmission(42);
- Wire.write(pwm_fan_value);
- Wire.endTransmission();
- Serial.println(pwm_fan_value);
- }
Add Comment
Please, Sign In to add comment