Go Down

Topic: Problem upload this program (Read 460 times) previous topic - next topic

deejonz

Hello,
I'm a newbe. I'm trying with very simple programs. When I try to upload this file my arduino freeze and I have to reset a lot of times before upload again a new program. It's only a test program that uses both a led and a servo.
If I remove the servo code lines it works perfectly.
The code is like this:

Code: [Select]

#include <Servo.h>
Servo myservo;
int ledPin = 13;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  myservo.attach(9);
}

void loop() {
  while (Serial.available() == 0);
 
  int val = Serial.read() - '0';

  if (val == 1) {
    Serial.println("Led is On");
    digitalWrite(ledPin, HIGH);
  } else if (val == 0) {
    Serial.println("Led is Off");
    digitalWrite(ledPin, LOW);
  } else {
    Serial.println("Move servo");
    myservo.write(30);
  }
}

what's wrong with that code?

Thank you.
Stefano.

johnwasser

The code looks correct to me.  I can't think of a good reason why that particular code would prevent new sketches from loading.  Perhaps the auto-reset of your Arduino is not working properly.  What model Arduino is it?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

deejonz

I have the arduino uno and I bought it 1 week ago!

johnwasser

I've read lots of mentions of some UNOs needing to have the firmware on the USB chip re-flashed because of USB problems.  Do a search for "DFU" to find out how to do that.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy