i have been working for 3 hours trying to make both my servo and my button work, but they just wont work together!
i couldent believe it when the button dident work becuase it is the esiest thing to do!
im really shocked that this isint working, and its making me mad becuase all i need is code, and my project is DONE!
heres myt code, and ive been trying MANY variations to make it work, but nothing seems to do it!:
#include <Servo.h>
Servo servo1; Servo servo2;
int val = 0;
int servopos = 180;
int but = 9;
void setup() {
pinMode(but, INPUT);
pinMode(1,OUTPUT);
servo1.attach(14); //analog pin 0 //servo1.setMaximumPulse(2000); //servo1.setMinimumPulse(700);
when the print ln returns, it comes with weird letter isntead of 1's and 0's!
hardware wise on the arduino:
pushbotton with one connected side that has 1 resistor leading to gnd, and 1 resistor leading to the pin
other side of pushbutton, that is not connected has a wire running to 5v...
digitalRead return boolean values HIGH and LOW, these are probably defined as byte values of 0 and 1 and println is sending raw bytes, not the ascii digits. Try the following:
if (digitalRead(but))
Serial.println(“1”);
else
Serial.println(“0”);
Its good practice to avoid using the underlying implementations of things like HIGH and LOW or TRUE and FALSE. Even if the code works, it may not work the same on other platforms.
Also, are you calling refresh()? You need to call this at least every 50 ms.
And why are you setting pin 1 as output, this is serial output and is set by the startup code.
yea, that output is there since the example code from the servo library, i dident know why it was there, so i dident want to take it out, i dident know if it was important or needed...
that button seems to be ok now, thanks for the help, but whenever i use the delay function in the sketch, the servo acts odd...
is there any way to use a delay in the sketchg to lets say tell the servo to go there, and then to another degree, and another degree?