Browse Source

Replace speaker with buzzer

master
Burathar 4 years ago
parent
commit
f532432d8b
  1. 136
      smoker.ino

136
smoker.ino

@ -48,17 +48,20 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); @@ -48,17 +48,20 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Queue tempQueue;
void setup() {
pinMode(SPEAKER_PIN, OUTPUT);
digitalWrite(SPEAKER_PIN, LOW);
//Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
//Serial.println(F("SSD1306 allocation failed"));
for(;;);
for (;;);
}
display.setRotation(2);
display.clearDisplay();
display.setTextColor(WHITE);
airTempSensor.preload();
}
void loop() {
updateAirTemp();
byte bUp = buttonUp.getState();
@ -66,12 +69,12 @@ void loop() { @@ -66,12 +69,12 @@ void loop() {
byte bLeft = buttonLeft.getState();
byte bRight = buttonRight.getState();
if (bRight >= 1){
if(state >= MAX_STATE) state = 0;
if (bRight >= 1) {
if (state >= MAX_STATE) state = 0;
else state += 1;
}
if (bLeft >= 1){
if(state <= 0) state = MAX_STATE;
if (bLeft >= 1) {
if (state <= 0) state = MAX_STATE;
else state -= 1;
}
@ -98,57 +101,60 @@ void loop() { @@ -98,57 +101,60 @@ void loop() {
display.display();
}
void updateAirTemp(){
void updateAirTemp() {
airTempSensor.update();
if(millis() - lastTempQueue > TEMP_PLOT_INTERVAL){
if (millis() - lastTempQueue > TEMP_PLOT_INTERVAL) {
tempQueue.push(airTempSensor.getTemperature());
lastTempQueue = millis();
}
}
void updateRelay(){
void updateRelay() {
float temperature = airTempSensor.getTemperature();
if (temperature - targetTemp >= TEMP_DELTA){ //Temp too high
if (temperature - targetTemp >= TEMP_DELTA) { //Temp too high
relay.off();
} else if (targetTemp - temperature >= TEMP_DELTA) { //Temp too low
relay.on();
}
if(temperature - targetTemp >= ALARM_TEMP_DELTA){
if (temperature - targetTemp >= ALARM_TEMP_DELTA) {
int second = millis() % 1000;
if(alarmState == 0 and second < 100){
if (alarmState == 0 and second < 100) {
alarmState = 1;
tone(SPEAKER_PIN, 440, 400);
}
if(alarmState == 1 and second > 500 and second < 600){
digitalWrite(SPEAKER_PIN, HIGH);
} else if (alarmState == 1 and second > 500 and second < 600) {
alarmState = 0;
tone(SPEAKER_PIN, 554, 400);
digitalWrite(SPEAKER_PIN, LOW);
} else if (alarmState == -1) {
digitalWrite(SPEAKER_PIN, LOW);
}
} else {
digitalWrite(SPEAKER_PIN, LOW);
}
}
void targetTempState(byte bUp, byte bDown){
void targetTempState(byte bUp, byte bDown) {
updateRelay();
switch(bUp){
switch (bUp) {
case 1:
targetTemp +=1;
targetTemp += 1;
break;
case 2:
targetTemp +=1;
targetTemp += 1;
break;
case 3:
targetTemp +=3;
targetTemp += 3;
break;
}
switch(bDown){
switch (bDown) {
case 1:
targetTemp -=1;
targetTemp -= 1;
break;
case 2:
targetTemp -=1;
targetTemp -= 1;
break;
case 3:
targetTemp -=3;
targetTemp -= 3;
break;
}
@ -156,10 +162,10 @@ void targetTempState(byte bUp, byte bDown){ @@ -156,10 +162,10 @@ void targetTempState(byte bUp, byte bDown){
// Target Temp
display.setTextSize(1);
display.setCursor(0,40);
display.setCursor(0, 40);
display.print("Target: ");
display.setTextSize(2);
display.setCursor(0,50);
display.setCursor(0, 50);
display.print(targetTemp);
display.print(" ");
display.setTextSize(1);
@ -182,81 +188,81 @@ void manualState(byte bUp, byte bDown) { @@ -182,81 +188,81 @@ void manualState(byte bUp, byte bDown) {
displayCurrentTemp();
display.setTextSize(1);
display.setCursor(0,40);
display.setCursor(0, 40);
display.print("Manual Mode");
display.setTextSize(2);
display.setCursor(0,50);
if (relay.getState()){
display.setCursor(0, 50);
if (relay.getState()) {
display.print("Heater ON");
} else {
display.print("Heater OFF");
}
}
void uptimeState(byte bUp, byte bDown){
void uptimeState(byte bUp, byte bDown) {
updateRelay();
unsigned int seconds = millis()/1000; //convect milliseconds to seconds
unsigned int minutes=seconds/60; //convert seconds to minutes
unsigned int hours=minutes/60; //convert minutes to hours
seconds=seconds-(minutes*60); //subtract the coverted seconds to minutes in order to display 59 secs max
minutes=minutes-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
unsigned int seconds = millis() / 1000; //convect milliseconds to seconds
unsigned int minutes = seconds / 60; //convert seconds to minutes
unsigned int hours = minutes / 60; //convert minutes to hours
seconds = seconds - (minutes * 60); //subtract the coverted seconds to minutes in order to display 59 secs max
minutes = minutes - (hours * 60); //subtract the coverted minutes to hours in order to display 59 minutes max
displayCurrentTemp();
display.setTextSize(1);
display.setCursor(0,40);
display.setCursor(0, 40);
display.print("Uptime:");
display.setTextSize(2);
display.setCursor(0,50);
if(hours < 10) display.print(0);
display.setCursor(0, 50);
if (hours < 10) display.print(0);
display.print(hours);
display.print(":");
if(minutes < 10) display.print(0);
if (minutes < 10) display.print(0);
display.print(minutes);
display.print(":");
if(seconds < 10) display.print(0);
if (seconds < 10) display.print(0);
display.print(seconds);
}
void displayMenuBar(){
void displayMenuBar() {
byte space = display.width() / (MAX_STATE + 1);
for (byte i = 0; i < MAX_STATE + 1; i++){
for (byte i = 0; i < MAX_STATE + 1; i++) {
if (i == state) display.fillCircle(space * i + space / 2, 3, 3, WHITE);
else display.drawCircle(space * i + space / 2, 3, 3, WHITE);
}
}
void tempPlotState(byte bUp, byte bDown){
void tempPlotState(byte bUp, byte bDown) {
updateRelay();
byte maxValue = tempQueue.getMax();
byte minValue = tempQueue.getMin();
if(minValue > 99) minValue = 99;
if (minValue > 99) minValue = 99;
display.setTextSize(1);
if(maxValue > 99)display.setCursor(110,8);
else display.setCursor(116,8);
if (maxValue > 99)display.setCursor(110, 8);
else display.setCursor(116, 8);
display.print(maxValue);
display.setCursor(116,57);
display.setCursor(116, 57);
display.print(minValue);
if(maxValue - minValue < 10){
if (maxValue - minValue < 10) {
minValue -= 1;
maxValue += 1;
}
for (int i=0; i<TEMP_QUEUE_LENGTH; i++){
for (int i = 0; i < TEMP_QUEUE_LENGTH; i++) {
byte barHeight = tempQueue.lookup(i);
if(barHeight < minValue) barHeight = minValue;
if (barHeight < minValue) barHeight = minValue;
barHeight = map(barHeight, minValue, maxValue, 2, 58);
display.fillRect(i * 2, SCREEN_HEIGHT - barHeight, 1, barHeight, WHITE);
}
}
void alarmSettingState(byte bUp, byte bDown){
void alarmSettingState(byte bUp, byte bDown) {
updateRelay();
if (bUp == 1) {
alarmState = 0;
}
@ -267,7 +273,7 @@ void alarmSettingState(byte bUp, byte bDown){ @@ -267,7 +273,7 @@ void alarmSettingState(byte bUp, byte bDown){
displayCurrentTemp();
display.setTextSize(1);
display.setCursor(0,40);
display.setCursor(0, 40);
display.print("Alarm temp: ");
display.print(targetTemp + ALARM_TEMP_DELTA);
display.print(" ");
@ -275,22 +281,22 @@ void alarmSettingState(byte bUp, byte bDown){ @@ -275,22 +281,22 @@ void alarmSettingState(byte bUp, byte bDown){
display.write(167);
display.setTextSize(1);
display.print("C");
display.setTextSize(2);
display.setCursor(0,50);
if (alarmState == -1){
display.setCursor(0, 50);
if (alarmState == -1) {
display.print("Alarm OFF");
} else {
display.print("Alarm ON");
}
}
void displayCurrentTemp(){
void displayCurrentTemp() {
display.setTextSize(1);
display.setCursor(0,10);
display.setCursor(0, 10);
display.print("Current: ");
display.setTextSize(2);
display.setCursor(0,20);
display.setCursor(0, 20);
display.print(airTempSensor.getTemperature());
display.print(" ");
display.setTextSize(1);

Loading…
Cancel
Save