Pages: [1]   Go Down
Author Topic: Problem upload this program  (Read 390 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 203
Posts: 8720
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 203
Posts: 8720
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: