<vexMotor.h>
<Servo.h>
const int DownButtonPin = 5; //green button ( i color-coded them)
const int UpButtonPin = 6; //brown button (These are toggle buttons)
const int GreenLEDPin = 2;// this LED will light up when the screen is going down
const int BlueLEDPin = 1;// this LED will light up when the screen is going up
int buttonState1 = 0;
int buttonState2 = 0;
vexMotor = myVexMotor1;
myVexMotor1.attach(9);
void setup() {
// put your setup code here, to run once:
///Serial.begin(9600);
pinMode(DownButtonPin, INPUT);
pinMode(UpButtonPin, INPUT);
pinMode(myVexMotor, OUTPUT);
pinMode(GreenLEDPin, OUTPUT);
pinMode(BlueLEDPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState1 = digitalRead(DownButtonPin);
buttonState2 = digitalRead(UpButtonPin);
if(buttonState1 == HIGH){
digitalWrite(GreenLEDPin, HIGH);
myVexMotor1.setFullSpeedCW(160);
}
else{
digitalWrite(GreenLEDPin, LOW);
myVexMotor1.setfullSpeedCW(0);
}
if(buttonState2 == HIGH){
digitalWrite(BlueLEDPin, HIGH);
myVexMotor1.setfullSpeedCWW(160);
}
else{
digitalWrite(BlueLEDPin, LOW);
myVewMotor1.setfullSpeedCWW(0);
}
}
I'm very new to programming, so if someone could help me with my code that would be awesome. Please give me advice on what I should fix and improve.
I tried using tutorials from multiple sources, but that didn't work out since there was a "no connection" error message.
Goal: there are two toggle buttons controlling the rotation of a motor. When one button is pressed, the motor will start moving CW and the green Led would light up. Once this button is pressed again, the CW rotation stops and the green Led turns off. The same process with the second button but this time, it controls the CWW rotation of the pole.
Any help would be appreciated.
Have a good day!
Please edit your post to remove your text with explanation from code block.
List all parts used in your project.
Show us how it's wired with hand made schematic.
Tell us where the "no connection" error message is coming from.
Hello @t3acat - Did you fix your arduino "no connection" problem? I started a simulation (link) for you to test. It doesn't do the "stop" part yet, and has a little debounce mess.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.