Lab 5 - TUI stove

Submitted by seanchen on Tue, 03/05/2013 - 23:49

Description

For this lab I designed a TUI that imitate the kitchen stove. The pot is used as the knob. When starting a fire, you need to push forward as you would do to the real stove. The push pressure is detected by FSR and a quite complex logic is used to calculate whether the fire can be turned on. While turing on the fire, the speaker makes a continuous clicking sound. After the fire is turned on, the LED represent the flame and their brightness is adjusted according to the knob position. Photocell is used to detect whether a pot is placed above. If a pot is placed for more than 2 seconds while the fire is on, the speaker will mimic the sound of a boiling pot until either the pot is removed or the fire is turned off.

One surprising finding is that the tone() will affect pin D3 and D11, which caused the LED to turn off when the speaker is making sound.

Components

1 x Arduino UNO Board

3 x LED lights with  220Ωresistors

1 x Potentiometers

1 x photocells with 10KΩ resistor

1 x FSR

1 x Peizo speaker

Code

const int photoPin = 0;   // select the input pin for the photocell
const int potPin = 1;   // select the input pin for the potentiometer
const int forcePin = 2;   // select the input pin for the FSR

int photoVal = 0;
int potVal = 0;
int forceVal = 0;

const int led1Pin = 9;
const int led2Pin = 10;
const int led3Pin = 6;

const int speakerPin = 13;

const int photoThres = 700;
const int potOriginal = 1020;
const int potThres = 900;
const int forceThres = 100;

boolean isFire = false;
boolean isPushed = false;
boolean isBeginTurn = false;
boolean isCooking = false;
unsigned long cookTime = 0;

void setup() {
pinMode(led1Pin, OUTPUT);  // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
pinMode(led3Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
pinMode(speakerPin, OUTPUT);

turnFire(0);

Serial.begin(9600);
}

void loop() {

Serial.print("photo: ");
Serial.print(photoVal);
Serial.print(", pot: ");
Serial.print(potVal);
Serial.print(", froce: ");
Serial.print(forceVal);
Serial.print(", fire: ");
Serial.print(isFire);
Serial.print(", push: ");
Serial.print(isPushed);
Serial.print(", begin turn: ");
Serial.print(isBeginTurn);
Serial.print(", cooking: ");
Serial.print(isCooking);
Serial.println();

if(forceVal > forceThres) {
isPushed = true;
} else {
isPushed = false;
isBeginTurn = false;
}

if(potVal >= potThres) { //turned off the fire
isFire = false;
turnFire(0);
noTone(speakerPin);
}

if(potVal < potThres && isBeginTurn) { //turned pass threshold
isFire = true;
noTone(speakerPin);
isBeginTurn = false;
}

if(isFire){ //fire on, deal with LED brightness
int fireVal = map(potVal, potThres, 0, 0, 256);
Serial.print("fire value ");
Serial.println(fireVal);
turnFire(fireVal);

//check for pot
if(photoVal < photoThres) {
if(!isCooking) {
Serial.println("just start cooking");
cookTime = millis();
}
isCooking = true;
if(millis()-cookTime > 2000) {
tone(speakerPin, 2093);
}
} else {
isCooking = false;
noTone(speakerPin);
}

} else { //fire not on, check whether user is trying to turn on
if(potVal >= potOriginal && isPushed){
isBeginTurn = true;
}
}

if(isBeginTurn) {
tone(speakerPin, 131, 10);
}

delay(100);
}

void turnFire(int value){
analogWrite(led1Pin, value);
analogWrite(led2Pin, value);
analogWrite(led3Pin, value);
}

Drupal theme by Kiwi Themes.