Blink works fine in standalone but code I wrote only works when rest pressed
hello everyone,
i looked on , cant find specific issue. i load code using arduino platform , place atmega328 in breadboard, blink works fine (without having press reset button). however, code below works if press reset button. after pressing reset button works fine.. i'm baffled i've seen surrounding breadboard atmega328 issues don't seem address unless i'm not connecting dots. i keep thinking i'm missing in loop setup i'm having problem finding it.
any appreciated. this first time i've created code adding someones existing code...
i looked on , cant find specific issue. i load code using arduino platform , place atmega328 in breadboard, blink works fine (without having press reset button). however, code below works if press reset button. after pressing reset button works fine.. i'm baffled i've seen surrounding breadboard atmega328 issues don't seem address unless i'm not connecting dots. i keep thinking i'm missing in loop setup i'm having problem finding it.
any appreciated. this first time i've created code adding someones existing code...
code: [select]
//bluetooth portion of code created by: angelo casimiro (4/27/14)
//voice activated arduino (bluetooth + android)
//feel free modify remember give credit
#include <servo.h>
string voice;
int light = 2; //connect led 1 pin #2
servo servo1;
void setup() {
serial.begin(9600);
serial.read();
pinmode(light, output);
int servopin=9;
servo1.attach(servopin);
servo1.write(0);
}
//-----------------------------------------------------------------------//
void loop() {
while (serial.available()){ //check if there available byte read
delay(10); //delay added make thing stable
char c = serial.read(); //conduct serial read
if (c == '#') {
break;
} //exit loop when # detected after word
if (c == '*') {
voice ="";
continue;
}
voice += c; //shorthand voice = voice + c
}
if (voice.length() > 0)
{
serial.println(voice);
if(voice == "servo on")
{
digitalwrite(light, high); //turn on led
servo1.write(90); //move servo 90 degrees
delay(100);
}
else if(voice == "servo off")
{
digitalwrite(light, low); //turn off light
servo1.write(178); //move servo 0 degrees
delay(100);
}
//-----------------------------------------------------------------------//
voice="";
}
} //reset variable after initiating
assuming have pull-up resistor on reset pin, might try add diode reset pin +5vdc, cathode wired +5vdc , anode reset pin.
current design used in uno , solve intermittent problem such seeing 1 had hit reset have sketch start after upload. small signal diode work.
current design used in uno , solve intermittent problem such seeing 1 had hit reset have sketch start after upload. small signal diode work.
Arduino Forum > Using Arduino > Project Guidance > Blink works fine in standalone but code I wrote only works when rest pressed
arduino
Comments
Post a Comment