Dear All,
I have been using my spark core as a timer for my nephews PlayStation for a year now - it worked fine.
I am a beginner to programming but it only took a few simple lines.
All I did was to add the following lines in the void loop() part of tinker
if( digitalRead(D1) == 1){goto one;}
if( digitalRead(D2) == 1){goto two;}
if( digitalRead(D6) == 1){goto six;}
goto start;
six:
digitalWrite(D7,HIGH);
delay (6000);
digitalWrite(D7,LOW);
goto start;
two:
digitalWrite(D7,HIGH);
delay (2000);
digitalWrite (D7,LOW);
goto start;
one:
digitalWrite(D7,HIGH);
delay (1000);
digitalWrite (D7,LOW);
goto start;
I dont know what happened but not it refuses to work now. Tinker does not seem to work with it. The core seems to be offline in tinker despite breathing cyan.
If I bring the physical inputs (D1, D2, D6) High it works- but tinker from my Android has been locked out. Plus to get the core back online I have to use putty to re-enter wifi credentials. Sometimes when I try to press the buttons on tinker it will make the core restart. It never used to do this - it was working fine.
//PUT YOUR VARIABLES HERE
int tinkerDigitalRead(String pin);
int tinkerDigitalWrite(String command);
int tinkerAnalogRead(String pin);
int tinkerAnalogWrite(String command);
void setup()
{
Spark.function("digitalread", tinkerDigitalRead);
Spark.function("digitalwrite", tinkerDigitalWrite);
Spark.function("analogread", tinkerAnalogRead);
Spark.function("analogwrite", tinkerAnalogWrite);
//PUT YOUR SETUP CODE HERE
pinMode(D7,OUTPUT);
pinMode(D1,INPUT_PULLDOWN);
pinMode(D2,INPUT_PULLDOWN);
pinMode(D6,INPUT_PULLDOWN);
}
void loop()
{
//PUT YOUR LOOP CODE HERE
start:
//int button2 = digitalRead(D2);
//int button6 = digitalRead(D6);
//int button1 = digitalRead(D1);
//if(button6==1){goto six;}
//if(button2==1){goto two;}
//if(button1==1){goto one;}
if( digitalRead(D1) == 1){goto one;}
if( digitalRead(D2) == 1){goto two;}
if( digitalRead(D6) == 1){goto six;}
goto start;
six:
digitalWrite(D7,HIGH);
delay (6000);
digitalWrite(D7,LOW);
goto start;
two:
digitalWrite(D7,HIGH);
delay (2000);
digitalWrite (D7,LOW);
goto start;
one:
digitalWrite(D7,HIGH);
delay (1000);
digitalWrite (D7,LOW);
goto start;
}
int tinkerDigitalRead(String pin) {
int pinNumber = pin.charAt(1) - '0';
if (pinNumber< 0 || pinNumber >7) return -1;
if(pin.startsWith("D")) {
pinMode(pinNumber, INPUT_PULLDOWN);
return digitalRead(pinNumber);}
else if (pin.startsWith("A")){
pinMode(pinNumber+10, INPUT_PULLDOWN);
return digitalRead(pinNumber+10);}
return -2;}
int tinkerDigitalWrite(String command){
bool value = 0;
int pinNumber = command.charAt(1) - '0';
if (pinNumber< 0 || pinNumber >7) return -1;
if(command.substring(3,7) == "HIGH") value = 1;
else if(command.substring(3,6) == "LOW") value = 0;
else return -2;
if(command.startsWith("D")){
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, value);
return 1;}
else if(command.startsWith("A")){
pinMode(pinNumber+10, OUTPUT);
digitalWrite(pinNumber+10, value);
return 1;}
else return -3;}
int tinkerAnalogRead(String pin){
int pinNumber = pin.charAt(1) - '0';
if (pinNumber< 0 || pinNumber >7) return -1;
if(pin.startsWith("D")){
pinMode(pinNumber, INPUT);
return analogRead(pinNumber);}
else if (pin.startsWith("A")){
pinMode(pinNumber+10, INPUT);
return analogRead(pinNumber+10);}
return -2;}
int tinkerAnalogWrite(String command){
int pinNumber = command.charAt(1) - '0';
if (pinNumber< 0 || pinNumber >7) return -1;
String value = command.substring(3);
if(command.startsWith("D")){
pinMode(pinNumber, OUTPUT);
analogWrite(pinNumber, value.toInt());
return 1;}
else if(command.startsWith("A")){
pinMode(pinNumber+10, OUTPUT);
analogWrite(pinNumber+10, value.toInt());
return 1;}
else return -2;}
Any help much appreciated