my wifly shield has a bit of an issue once i program it once, it works fine however when i pull the usb out of my laptop and plug it back in, suddenly it stops. if i hit the rest switch it works great again, so i was wondering how to implement a reset switch below is my code
#include <SPI.h>
#include <WiFly.h>
#include <Wire.h>
WiFlyServer server(2000);
int led = 47;
String readString;
char c;
int i;
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void setup() {
WiFly.begin();
Serial.begin(9600);
Serial3.begin(9600);
server.begin();
//SPI.begin();
pinMode(led, OUTPUT);
}
void loop() {
//resetFunc();
WiFlyClient client = server.available();
if (client.connect()){
while (client.available()) {
c = client.read();
readString += c; //makes the string readString
delay(5); //slow looping to allow buffer to fill with next character
break;
}
if (readString.length() >0){
int commaIndex = readString.indexOf(',');
int secondCommaIndex = readString.indexOf(',', commaIndex+1);
String firstValue = readString.substring(0, commaIndex);
String secondValue = readString.substring(commaIndex+1, secondCommaIndex);
String thirdValue = readString.substring(secondCommaIndex+1); // To the end of the string
int x = firstValue.toInt();
int y = secondValue.toInt();
int z = thirdValue.toInt();
Serial.println(x);
if(x == 5){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
}
}
}
if (!client.connected() || !server.available()){
while(SpiSerial.available() > 0) {
#if ARDUINO >= 100
Serial3.write(SpiSerial.read());
#else
Serial3.print(SpiSerial.read(), BYTE);
#endif
}
if(Serial3.available()) { // Outgoing data
#if ARDUINO >= 100
SpiSerial.write(Serial3.read());
#else
SpiSerial.print(Serial3.read(), BYTE);
#endif
}
}
readString=""; //empty for next input
}
If you unplug the USB cable, removing power from the Arduino, and then reconnect it, all the hardware is completely reset, and you should not have to press the reset button.
What you do need to explain is just how things are wired/powered, and to post ALL of your code.
If you unplug the USB cable, removing power from the Arduino, and then reconnect it, all the hardware is completely reset, and you should not have to press the reset button.
What you do need to explain is just how things are wired/powered, and to post ALL of your code.
i see what yo u mean, i thought that if i unplug the usb and re power it, it should still run the code as normal however it doesn't and i am completely lost i will post my code below
#include <SPI.h>
#include <WiFly.h>
#include <Wire.h>
WiFlyServer server(2000);
//byte address = 0x11;
//int CS= 10;
int led = 47;
String readString;
String readString2;
char c;
int i;
char d;
//int photocellReading;
int number_4 = 255;
int number_5 = 111;
int number_6 = 93;
int number_7 = 75;
int number_8 = 56;
int number_9 = 38;
int number_10 = 18;
int number_11 = 0;
int pwmpin = 9;
void setup() {
WiFly.begin();
Serial.begin(9600);
Serial3.begin(9600);
Serial2.begin(9600);
server.begin();
//pinMode (CS, OUTPUT);
//SPI.begin();
pinMode(led, OUTPUT);
pinMode(pwmpin, OUTPUT);
}
void loop() {
//resetFunc();
WiFlyClient client = server.available();
if(Serial2.available()){
while(Serial2.available() > 0) {
char d = Serial2.read(); //gets one byte from serial buffer
readString2 += d; //makes the string readString
delay(5); //slow looping to allow buffer to fill with next character
}
if (readString2.length() >0){
int commaIndex2 = readString2.indexOf(',');
int secondCommaIndex2 = readString2.indexOf(',', commaIndex2+1);
String firstValue2 = readString2.substring(0, commaIndex2);
String secondValue2 = readString2.substring(commaIndex2+1, secondCommaIndex2);
String thirdValue2 = readString2.substring(secondCommaIndex2+1); // To the end of the string
int x2 = firstValue2.toInt();
int y2 = secondValue2.toInt();
int z2 = thirdValue2.toInt();
if(x2 == 200){
if(y2 == 4){
digitalWrite(led, LOW);
}
}
}
//empty for next input
}
if (client.connect()){
while (client.available()) {
c = client.read();
readString += c; //makes the string readString
delay(5); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0){
int commaIndex = readString.indexOf(',');
int secondCommaIndex = readString.indexOf(',', commaIndex+1);
String firstValue = readString.substring(0, commaIndex);
String secondValue = readString.substring(commaIndex+1, secondCommaIndex);
String thirdValue = readString.substring(secondCommaIndex+1); // To the end of the string
int x = firstValue.toInt();
int y = secondValue.toInt();
int z = thirdValue.toInt();
Serial.println(x);
if(x == 4){
digitalWrite(led, HIGH);
//digitalWrite(CS, LOW);
//SPI.transfer(address);
//SPI.transfer(number_4);
//digitalWrite(CS, HIGH);
analogWrite(pwmpin, number_4);
}
}
}
if (!client.connected() || !server.available()){
while(SpiSerial.available() > 0) {
#if ARDUINO >= 100
Serial3.write(SpiSerial.read());
#else
Serial3.print(SpiSerial.read(), BYTE);
#endif
delay(100);
}
if(Serial3.available()) { // Outgoing data
#if ARDUINO >= 100
SpiSerial.write(Serial3.read());
#else
SpiSerial.print(Serial3.read(), BYTE);
#endif
}
}
readString=""; //empty for next input
readString2="";
}