xxxxxxxxxx
196
function setup() {
createCanvas(1466,768);
textSize(18);
textFont('VT323');
start_button_obj = new breathing_button(width-90, height-70,"START");
next_button_obj = new breathing_button(width-90, height-70,"NEXT");
restart_button_obj = new breathing_button(width-90, height-70,"RESTART");
// clock code from: https://p5js.org/examples/input-clock.html
let radius = min(width, height) / 2;
secondsRadius = radius * 0.5;
minutesRadius = radius * 0.4;
hoursRadius = radius * 0.3;
clockDiameter = radius * 1.7;
cx = 810;
cy = 330;
}
function draw() {
// print(next_button_state);
// one value from Arduino controls the background's red color
background("black");
// the other value controls the text's transparency value
// fill(255, 0, 255, map(alpha, 0, 1023, 0, 255));
fill("white");
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
}
// the project code
if (gameState == 'temp') {
temp_page();
} else if (gameState == 'instructions') {
instructions();
}
else if(gameState == "start"){
start();
}
else if(gameState == "dry_ing"){
dry_ing();
}
else if (gameState == "mix_dry_ing")
{
mix_dry_ing();
}
else if (gameState == "wet_ing")
{
wet_ing();
}
else if (gameState == "add_Saffron_and_cardamom")
{
add_Saffron_and_cardamom();
}
else if (gameState == "mix_batter")
{
mix_batter();
}
else if (gameState == "pour_batter")
{
pour_batter();
}
else if (gameState == "place_in_oven")
{
place_in_oven();
}
else if (gameState == "timer")
{
timer();
}
else if (gameState == 'end') {
end();
}
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
function readSerial(data) {
////////////////////////////////////
//READ FROM ARDUINO HERE
////////////////////////////////////
if (data != null) {
// make sure there is actually a message
// split the message
let fromArduino = split(trim(data), ",");
// print(fromArduino);
// if the right length, then proceed
if (fromArduino.length == 6) {
// only store values here
// print(fromArduino);
// do everything with those values in the main draw loop
// oven_knob = fromArduino[0];
oven_knob = map(fromArduino[0],0,1023,130,0);
mixing_sensor = fromArduino[1];
pour_sensor = fromArduino[2];
picking_ingredient = fromArduino[3]; //returns distance from sensor in cm
next_button_state = fromArduino[4]
// print("ard"+fromArduino[4]);
oven_door_open = fromArduino[5];
}
//////////////////////////////////
//SEND TO ARDUINO HERE (handshake)
//////////////////////////////////
let sendToArduino = oven_led_state + "\n";
writeSerial(sendToArduino);
}
}
//Arudino Code
/*
// function: blink the LEDs and the green button changes the pattern
int pushButton_green = A2;
int pushButton_yellow = A3;
int first = 13; //connected to the green
int second = 12; //connected to the blue
int pressed = 0;
#define LED_one first
#define LED_two second
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton_green, INPUT);
pinMode(pushButton_yellow, INPUT);
pinMode(LED_one,OUTPUT);
pinMode(LED_two,OUTPUT);
digitalWrite(LED_one, LOW);
digitalWrite(LED_two, LOW);
}
void loop() {
// read the input pin:
int buttonState_g = digitalRead(pushButton_green);
// Serial.println(buttonState_g);
int buttonState_y = digitalRead(pushButton_yellow);
// Serial.println(buttonState_y);
// delay(1);
if (buttonState_y)
{
digitalWrite(LED_one, LOW);
digitalWrite(LED_two, HIGH);
delay(100);
digitalWrite(LED_one, HIGH);
digitalWrite(LED_two, LOW);
delay(500);
}
if (buttonState_g)
{
if (pressed == 0)
{
int temp = first;
first = second;
second = temp;
pressed = 1;
}
}
else{
pressed = 0;
}
}
*/