Hi all.
I have the following code in Arduino that when on initialisation it starts by blinking a led, and only when a command (letter) is sent over the Serial Monitor, the led stops blinking. The stop phase lasts for a little less than 2 minutes, and then starts blinking again, and so on.
The code works fine when I use the Serial Monitor. However, when I do the same in Processing (code below), the led receives the 'a' letter and stops blinking, but never starts again.
Can someone explain why??
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
float startMin;
float setRandMin;
float count = 0;
int newCount = 0;
int led1 = 13;
char input;
boolean starter = true;
void setup () {
Serial.begin(9600);
pinMode(led1, OUTPUT);
// following line sets the RTC to the date & time this sketch was compiled
RTC.begin(DateTime(__DATE__, __TIME__));
DateTime now = RTC.now();
startMin = now.minute();
setRandMin = 1;
}
void loop () {
if (Serial.available()) {
input = Serial.read();
}
DateTime now = RTC.now();
if (startMin != now.minute()) {
count = count + 1;
}
newCount = count / 60.;
if (newCount >= setRandMin || starter) {
float led1Bool = random (0, 2);
if (led1Bool > 0.7) {
digitalWrite (led1, HIGH);
}
else {
digitalWrite(led1, LOW);
}
delay(200);
}
else {
delay(1000);
}
if (input == 'A' || input == 'a') {
starter = false;
startMin = now.minute();
setRandMin = 1;
count = 0;
digitalWrite(led1, LOW);
}
}
/////// Processing Code //////////
import processing.serial.*;
Serial myPort;
void setup() {
println(Serial.list());
myPort = new Serial (this, Serial.list()[0], 9600);
}
void draw() {
}
void mouseReleased() {
myPort.write(65);
}
///////////////////////////////////