/* This programme uses the 85 degree low temperature curing cycle to programme the Atmega32U4 chip on the carbon ply carbon fibre curing oven. */ #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif #ifdef U8X8_HAVE_HW_I2C #include #endif //constructor for the OLED screen U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 3, 2); //defining the constant variables for the pins const int relayPin = 12; const int powerledPin = 13; const int heaterledPin = 5; const int programmedledPin = 10; const int modebuttonPin = A5; const int downbuttonPin = A4; const int upbuttonPin = A3; const int ThermistorPin = A1; //turning on the power LED and programmed LED int powerled = HIGH ; int heaterled = LOW; int programmedled = HIGH; int timeMins = 0; //current time in minutes int timeLeft = 900; //amount of time left in programme. //variables for button press/debounce int downbuttonState; // the current reading from the input pin int lastdownbuttonState = LOW; // the previous reading from the input pin int upbuttonState; // the current reading from the input pin int lastupbuttonState = LOW; // the previous reading from the input pin // the following variables are unsigned longs because the time, measured in // milliseconds, will quickly become a bigger number than can be stored in an int. unsigned long lastdownDebounceTime = 0; // the last time the output pin was toggled unsigned long downdebounceDelay = 50; // the debounce time; increase if the output flickers unsigned long lastupDebounceTime = 0; // the last time the output pin was toggled unsigned long updebounceDelay = 50; // the debounce time; increase if the output flickers //set initial target temperature int setTemp = 30; //may need to be float in some programmes? //set initial variables used to calculate temperature int Vo; float R1 = 10000; float logR2, R2, T; float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; float powervoltage=5;//define the power supply voltage. //SETUP void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); //Define pins to be used as output pinMode(relayPin,OUTPUT); pinMode(powerledPin,OUTPUT); pinMode(heaterledPin,OUTPUT); pinMode(programmedledPin,OUTPUT); //Define pins to be used as input pinMode(modebuttonPin,INPUT); pinMode(downbuttonPin,INPUT); pinMode(upbuttonPin,INPUT); pinMode(ThermistorPin, INPUT); //initialise the u8g2 OLED screen u8g2.begin(); //allow printing of variables on the screen u8g2.enableUTF8Print(); } // the loop routine runs over and over again forever: void loop() { digitalWrite(powerledPin,HIGH); digitalWrite(programmedledPin,LOW); int downreading = digitalRead(downbuttonPin); int upreading = digitalRead(upbuttonPin); Vo = analogRead(ThermistorPin); R2 = R1 * (1023.0 / (float)Vo - 1.0); logR2 = log(R2); T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); T = T - 273.15; //T=23.5; //Serial.print("Temperature: "); //Serial.println(T); timeMins = millis()/1000/60; //setTemp = 20; //Serial.println(setTemp); if(T downdebounceDelay) { // whatever the reading is at, it's been there for longer than the debounce // delay, so take it as the actual current state: // if the button state has changed: if (downreading != downbuttonState) { downbuttonState = downreading; // only toggle the LED if the new button state is HIGH if (downbuttonState == HIGH) { //ledState = !ledState; setTemp=setTemp - 1; //Serial.println(setTemp); delay(1200); } } } // set the LED: //digitalWrite(ledPin, ledState); // save the reading. Next time through the loop, it'll be the lastdownbuttonState: lastdownbuttonState = downreading; ////UP BUTTON STARTS HERE if (upreading != lastupbuttonState) { // reset the debouncing timer lastupDebounceTime = millis(); } if ((millis() - lastupDebounceTime) > updebounceDelay) { // whatever the reading is at, it's been there for longer than the debounce // delay, so take it as the actual current state: // if the button state has changed: if (upreading != upbuttonState) { upbuttonState = upreading; // only toggle the LED if the new button state is HIGH if (upbuttonState == HIGH) { //ledState = !ledState; setTemp=setTemp + 1; //Serial.println(setTemp); delay(1200); } } } // set the LED: //digitalWrite(ledPin, ledState); // save the reading. Next time through the loop, it'll be the lastdownbuttonState: lastupbuttonState = upreading; Serial.println(T); //delay(500); }