xxxxxxxxxx
84
let serial;
var currentDate;
var currentTime;
function setup() {
createCanvas(400, 400);
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
}
button = createButton("display on arduino");
button.position(20,150);
}
function draw() {
// background(220);
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);
button.mousePressed(send_data);
// send_data();
background(32);
fill(255);
noStroke();
textSize(24);
text(currentDate, 40, 40);
text(currentTime, 40, 70);
}
function send_data() {
writeSerial(currentDate);
print(currentDate);
}
// function clicked() {
// // SEND A FARSI LETTER - TRANSLATE IT IN THE ARDUINO CODE
// // print(value);
// // SEND IT THROUGH A FOR LOOP
// for (i=0; i<value.length;i++) {
// writeSerial(value[i]);
// print(value[i]);
// }
// }
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);
// }
// }