Guest User

Untitled

a guest
Feb 15th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.95 KB | None | 0 0
  1.  
  2. // Project: DIY Thermocyler V2.0 Arduino
  3. // Creator: Tobias and Torben
  4. // Date of Creation: 10.12.16
  5.  
  6. #include "Nextion.h"
  7. #include <SoftwareSerial.h>
  8. #include <Wire.h>
  9.  
  10.  
  11. SoftwareSerial HMISerial(10,11); //RX,TX
  12. //SoftwareSerial ardserial(4,5); //RX,TX
  13.  
  14.  
  15.  
  16. int cycle = 0;
  17. int repe  = 0;
  18. int cycle_help = 0;
  19. int cycle_help_temp = 0;
  20. int cycle_temp[10];
  21. int cycle_time[10];
  22.  
  23. //----------------------------------------------------------------------------------------------------------------------
  24. //Nextions Display Buttons
  25.  
  26. //Home Screen
  27. NexButton start     = NexButton(0,1,"start");
  28. NexButton c_time    = NexButton(0,3,"C_time");
  29. NexButton c_temp    = NexButton(0,4,"b3");
  30. //Nextion Test Mode Buttons
  31. NexButton heat      = NexButton(1,1,"heat");
  32. NexButton cool      = NexButton(1,2,"cool");
  33. NexSlider pwm_heat  = NexSlider(1,6,"pwm_heat");
  34. NexSlider pwm_fan   = NexSlider(1,5,"pwm_fan");
  35. //Nextion Cycle Buttons/Nummber
  36. NexButton check     = NexButton(2,12,"check");
  37. NexNumber n_cycle   = NexNumber(2,16,"n_cycle");
  38. //Nextion Repetion Buttons/Nummber
  39. NexButton check_rep = NexButton(5,6,"check");
  40. NexNumber n_cycle_rep = NexNumber(5,5,"n_cycle");
  41. //Nextion Cycle Time Buttons/Nummber
  42. NexButton check_t   = NexButton(3,10,"check");
  43. NexButton next_t    = NexButton(3,6,"b13");
  44. NexButton back_t    = NexButton(3,5,"b12");
  45. NexNumber n_cycle_t = NexNumber(3,2,"n_cycle");
  46. NexNumber n_cycle_c = NexNumber(3,7,"n0");
  47. //Nextion Cycle Temp Buttons/Nummber
  48. NexButton check_temp   = NexButton(4,10,"b11");
  49. NexButton next_temp    = NexButton(4,6,"b13");
  50. NexButton back_temp    = NexButton(4,5,"b12");
  51. NexNumber n_cycle_temp = NexNumber(4,2,"n_cycle");
  52. NexNumber n_cycle_c_temp = NexNumber(4,7,"n0");
  53.  
  54. //----------------------------------------------------------------------------------------------------------------------
  55. char buffer[100] = {0};
  56.  
  57. //Button Press abfrage
  58. NexTouch *nex_listen_list[] = {
  59.    
  60.    
  61.     &heat,
  62.     &cool,
  63.     &pwm_heat,
  64.     &pwm_fan,
  65.     &check,
  66.     &check_rep,
  67.     &check_t,
  68.     &next_t,
  69.     &back_t,
  70.     &start,
  71.     &c_time,
  72.     &check_temp,
  73.     &next_temp,
  74.     &back_temp,
  75.     &c_temp,
  76.     NULL
  77.  
  78. };
  79. //----------------------------------------------------------------------------------------------------------------------
  80. //Arduino Inilisation
  81. void setup() {
  82.   Wire.begin(55);
  83.   nexInit();
  84.   Serial.begin(38400);
  85.   //ardserial.begin();
  86.   while (!Serial){
  87.    
  88.   }
  89.  
  90.  
  91.  
  92.   Serial.println("USB-to-PC Connection etablished");  
  93. //----------------------------------------------------------------------------------------------------------------------
  94. //Attach Button Funktions
  95. //Home Screen BUttons
  96.   start.attachPush(start_cycle, &start);
  97.   c_time.attachPush(cycle_time_button,&c_time);
  98.   c_temp.attachPush(cycle_temp_button,&c_temp);
  99.  
  100. //Attach Test Mode Buttons  
  101.   heat.attachPush(heat_button, &heat);
  102.   cool.attachPush(cool_button, &cool);
  103.   pwm_heat.attachPop(pwm_heat_slider, &pwm_heat);
  104.   pwm_fan.attachPop(pwm_fan_slider, &pwm_fan);
  105.  
  106. //Attach Cycle Buttons
  107.   check.attachPush(check_cycle_button, &check);
  108. //Attach Repetion Buttons
  109.   check_rep.attachPush(check_repe_button,&check_rep);
  110. //Attach Time Buttons
  111.   check_t.attachPush(check_time_button,&check_t);
  112.   next_t.attachPush(next_t_button,&next_t);
  113.   back_t.attachPush(back_t_button,&back_t);
  114. //Attach Temperatur Buttons
  115.   check_temp.attachPush(check_temp_button,&check_temp);
  116.   next_temp.attachPush(next_temp_button,&next_temp);
  117.   back_temp.attachPush(back_temp_button,&back_temp);
  118.  
  119.  
  120. //----------------------------------------------------------------------------------------------------------------------
  121. Serial.println("Setup Complet");
  122. }
  123. //Main Loop waiting for actions
  124. void loop() {
  125.  
  126.   nexLoop(nex_listen_list);
  127.  
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------------------------------------
  131. //start Cycle
  132. void start_cycle(void *ptr){
  133.   sendData();
  134.    
  135. }
  136. //----------------------------------------------------------------------------------------------------------------------
  137. //sending data funktio
  138. void sendData(){
  139.   int temp_ok = 0;
  140.   int time_ok = 0;
  141.   int cycle_ok = 0;
  142.   int i = 0;
  143.   while(!Serial){
  144.     while(cycle_ok == 0){
  145.       Serial.print('S');
  146.       cycle_ok = Serial.read();
  147.     }
  148.     Serial.print(cycle);
  149.     while(temp_ok == 0){
  150.       temp_ok  = Serial.read();
  151.      
  152.     }
  153.     for (byte i = 0; i < (sizeof(cycle_temp)/sizeof(cycle_temp[0])); i++) {
  154.     Serial.print(cycle_temp[i]);
  155.     }
  156.     i = 0;
  157.     while(time_ok == 0){
  158.       time_ok = Serial.read();  
  159.     }
  160.  
  161.     for (byte i = 0; i < (sizeof(cycle_time)/sizeof(cycle_time[0])); i++) {
  162.     Serial.print(cycle_time[i]);
  163.     }
  164.     i = 0;
  165.     delay(100);
  166.     Serial.print("Finished");
  167.    
  168.   }
  169.  
  170.  
  171. }
  172. //----------------------------------------------------------------------------------------------------------------------
  173. //Read Data from Nextion
  174. //Receving number of cycles
  175. void check_cycle_button(void *ptr){
  176.   uint32_t cycle_value_value = 0;
  177.   n_cycle.getValue(&cycle_value_value);
  178.   cycle = cycle_value_value;
  179.  }
  180. //Receving number of Repetions
  181. void check_repe_button(void *ptr){
  182.   uint32_t repe_value = 0;
  183.   n_cycle_rep.getValue(&repe_value);
  184.   repe = repe_value;
  185.  }
  186. //Cycle Temperature
  187. //----------------------------------------------------------
  188. void cycle_temp_button(void *ptr){
  189.     //This is needed if you leave it and join it again
  190.     n_cycle_temp.setValue(cycle_temp[0]);
  191.     Serial.print("test");
  192.    
  193. }
  194. void check_temp_button(void *ptr){
  195.  
  196.   for (int h = 0; h < cycle+1;h++){
  197.     Serial.print(cycle_temp[h]);  
  198.   }
  199.  
  200. }
  201. //Temp for each Cycle
  202. void next_temp_button(void *ptr){
  203.   uint32_t cycle_temp_value = 0;
  204.  
  205. //  cycle = EEPROM.read(200);
  206.  
  207.   if (cycle_help_temp == cycle){
  208.     n_cycle_temp.getValue(&cycle_temp_value);
  209.     cycle_temp[cycle_help_temp] = cycle_temp_value;
  210.     cycle_help_temp = 0;
  211.     n_cycle_temp.setValue(cycle_time[cycle_help_temp]);
  212.     n_cycle_c_temp.setValue(cycle_help_temp);
  213.   }else {
  214.     n_cycle_temp.getValue(&cycle_temp_value);
  215.     cycle_temp[cycle_help_temp] = cycle_temp_value;
  216.     ++cycle_help_temp;  
  217.     n_cycle_c_temp.setValue(cycle_help_temp);
  218.     n_cycle_temp.setValue(cycle_temp[cycle_help_temp]);
  219.  }
  220.  
  221.    
  222. }
  223. void back_temp_button(void *ptr){
  224.   if (cycle_help_temp == 0){
  225.     cycle_help_temp = cycle;
  226.     n_cycle_temp.setValue(cycle_temp[cycle_help_temp]);
  227.     n_cycle_c_temp.setValue(cycle_help_temp);
  228.   }else {
  229.     --cycle_help_temp;
  230.    
  231.     n_cycle_temp.setValue(cycle_temp[cycle_help_temp]);
  232.     n_cycle_c_temp.setValue(cycle_help_temp);
  233.   }
  234.  
  235.    
  236. }
  237.  
  238. //----------------------------------------------------------
  239. //Cycle Time
  240. //Time of each Cycles
  241. void cycle_time_button(void *ptr){
  242.     //This is needed if you leave it and join it again
  243.     n_cycle_t.setValue(cycle_time[0]);
  244.     Serial.print("test");
  245.    
  246. }
  247. void check_time_button(void *ptr){
  248.  
  249.   for (int h = 0; h < cycle+1;h++){
  250.     Serial.print(cycle_time[h]);  
  251.   }
  252.  
  253. }
  254. //Temp for each Cycle
  255. void next_t_button(void *ptr){
  256.   uint32_t cycle_t_value = 0;
  257.  
  258. //  cycle = EEPROM.read(200);
  259.   Serial.print("Ich gehe hier rein");
  260.   if (cycle_help == cycle){
  261.     n_cycle_t.getValue(&cycle_t_value);
  262.     cycle_time[cycle_help] = cycle_t_value;
  263.     cycle_help = 0;
  264.     n_cycle_t.setValue(cycle_time[cycle_help]);
  265.     n_cycle_c.setValue(cycle_help);
  266.   }else {
  267.     n_cycle_t.getValue(&cycle_t_value);
  268.     cycle_time[cycle_help] = cycle_t_value;
  269.     ++cycle_help;  
  270.     n_cycle_c.setValue(cycle_help);
  271.     n_cycle_t.setValue(cycle_time[cycle_help]);
  272.  }
  273.  
  274.  
  275.  
  276.    
  277. }
  278. void back_t_button(void *ptr){
  279.   if (cycle_help == 0){
  280.     cycle_help = cycle;
  281.     n_cycle_t.setValue(cycle_time[cycle_help]);
  282.     n_cycle_c.setValue(cycle_help);
  283.   }else {
  284.     --cycle_help;
  285.    
  286.     n_cycle_t.setValue(cycle_time[cycle_help]);
  287.     n_cycle_c.setValue(cycle_help);
  288.   }
  289.  
  290.    
  291. }
  292. //----------------------------------------------------------
  293. //----------------------------------------------------------------------------------------------------------------------
  294. //Begin Test Mode
  295. bool stop;void heat_button (void *ptr){
  296.  
  297.   Wire.beginTransmission(52);
  298.   Wire.write('H');
  299.   Wire.endTransmission();  
  300.   Serial.print("Test");
  301.  
  302.  
  303. }  
  304. void cool_button (void *ptr){
  305.  
  306.   Wire.beginTransmission(52);
  307.   Wire.write('C');
  308.   Wire.endTransmission();
  309.  
  310.  
  311.  
  312.  
  313. }
  314. void pwm_heat_slider (void *ptr){
  315.   uint32_t pwm_heat_value = 0;
  316.   pwm_heat.getValue(&pwm_heat_value);
  317.   Wire.beginTransmission(42);
  318.   Wire.write('V');
  319.   Wire.endTransmission();
  320.   Wire.beginTransmission(42);
  321.   Wire.write(pwm_heat_value);
  322.  
  323.  
  324.   Serial.println(pwm_heat_value);
  325.  
  326. }
  327. void pwm_fan_slider (void *ptr){
  328.   uint32_t pwm_fan_value = 0;
  329.   pwm_fan.getValue(&pwm_fan_value);
  330.   Wire.beginTransmission(42);
  331.   Wire.write('F');
  332.   Wire.endTransmission();
  333.   Wire.beginTransmission(42);
  334.   Wire.write(pwm_fan_value);
  335.   Wire.endTransmission();
  336.   Serial.println(pwm_fan_value);
  337.  
  338.  
  339. }
Add Comment
Please, Sign In to add comment