Advertisement
Guest User

Untitled

a guest
Jan 15th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. //for Arduino bud toaster, battery powered. more comments to come!
  2. #include "nokia_3310_lcd.h"
  3. #include "avr_bmp.h"
  4. #include<stdlib.h>
  5. #include <PID_v1.h>
  6.  
  7. //Define PID Variables
  8. double Setpoint, Input, Output;
  9. //Specify the links and initial tuning parameters
  10. PID myPID(&Input, &Output, &Setpoint,4,0.1,5, DIRECT);
  11.  
  12. #include <MAX6675.h>
  13. int thermoDO = 4;
  14. int thermoCS = 3;
  15. int thermoCLK = 2;
  16. MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
  17.  
  18.  
  19. Nokia_3310_lcd lcd=Nokia_3310_lcd();
  20.  
  21. char string1[]="0000";
  22.  
  23. void setup()
  24. {
  25.   Serial.begin(9600);
  26. //initialise LCD
  27.   lcd.LCD_3310_init();
  28.   lcd.LCD_3310_clear();
  29.  
  30.   Input = thermocouple.readCelsius();
  31.   Setpoint = 190;
  32.  
  33.   //turn the PID on
  34.   myPID.SetMode(AUTOMATIC);
  35. //write initial describers to the LCD
  36.   lcd.LCD_3310_write_string(0, 0, " Cur    Set", MENU_NORMAL );
  37.   lcd.LCD_3310_write_string(35, 4, "@C", MENU_NORMAL);
  38.  
  39. }
  40.  
  41. void loop()
  42. {
  43. //PID stuff:
  44.   Input = thermocouple.readCelsius();
  45.   myPID.Compute();
  46.   int out = map(Output, 0, 255, 0, 100);
  47.   analogWrite(5,out);
  48.  
  49. //write temp to the LCD
  50.   dtostrf(Input,3,0,string1);
  51.   lcd.LCD_3310_write_string_big(0, 1, string1, MENU_NORMAL);
  52.   dtostrf(Setpoint,3,0,string1);
  53.   lcd.LCD_3310_write_string_big(42, 1, string1, MENU_NORMAL);
  54.   dtostrf(out,4,1,string1);
  55.   lcd.LCD_3310_write_string(0, 4, string1, MENU_NORMAL);
  56.   delay(200);
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement