xxxxxxxxxx
143
let serial;
let txt;
let flag;
var currentDate;
var currentTime;
var button_col = "grey";
function setup() {
createCanvas(1420,900);
if (!serialActive) {
text("Press = to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
}
// button for the game
welcome_button = createButton("what is this?");
welcome_button.position(450,300);
welcome_button.size(600, 100);
welcome_button.style("font-family", "Courier New");
welcome_button.style("font-size", "30px");
welcome_button.style('background-color', button_col);
welcome_button.style("border-width", "10px");
welcome_button.style("border-color", "white");
// button to send input to arduino
calendar_button = createButton("display shamsi date and time");
calendar_button.position(450,450);
calendar_button.size(600, 100);
calendar_button.style("font-family", "Courier New");
calendar_button.style("font-size", "30px");
calendar_button.style('background-color', button_col);
calendar_button.style("border-width", "10px");
calendar_button.style("border-color", "white");
// game_button.mousePressed(game_event);
// button for displaying time and date
game_button = createButton("play the barrier game");
game_button.position(450,600);
game_button.size(600, 100);
game_button.style("font-family", "Courier New");
game_button.style("font-size", "30px");
game_button.style('background-color', button_col);
game_button.style("border-width", "10px");
game_button.style("border-color", "white");
// calendar_button.mousePressed(calendar_event);
// reset_button = createButton("reset");
// reset_button.position(450,750);
// reset_button.size(600, 100);
// reset_button.style("font-family", "Courier New");
// reset_button.style("font-size", "30px");
// reset_button.style('background-color', button_col);
// reset_button.style("border-width", "10px");
// reset_button.style("border-color", "white");
}
function draw() {
background(0);
var currentYear = year();
var currentMonth = month();
var currentDay = day();
var currentHour = hour();
var currentMinute = minute();
var currentSecond = second();
currentDate = currentYear + '-' + nf(currentMonth, 2) + '-' + nf(currentDay, 2);
currentTime = currentHour + ':' + nf(currentMinute, 2) + ':' + nf(currentSecond, 2);
fill(200);
noStroke();
textSize(20);
text(currentDate, 690, 170);
text(currentTime, 700, 200);
// sending data
welcome_button.mousePressed(quote_event);
calendar_button.mousePressed(calendar_event);
game_button.mousePressed(game_event);
// reset_button.mousePressed(reset_sketch);
}
function quote_event() {
txt = "ok so idk"
flag = "1";
writeSerial(flag, txt);
}
function calendar_event() {
flag = "2";
writeSerial(flag, currentDate);
}
function game_event() {
flag = "3";
writeSerial(flag);
}
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) {
// print("we are here");
// //////////////////////////////////
// //SEND TO ARDUINO HERE (handshake)
// //////////////////////////////////
// let sendToArduino = value;
// writeSerial(sendToArduino);
// print(sendToArduino);
// }
// }
function mousePressed() {
if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
let fs = fullscreen();
fullscreen(!fs);
}
}
function reset_sketch() {
draw();
}