The program keeps saying it has a missing (}) even though i kept adding one to fine the expected (}) there isnt one i tried it on everything
Switch1 - on and off
Switch 2 - lowRPM
Switch 3 - highRPM
ctrl-T, post in code tags — then we can look at your code.
You may find the missing indents after the Ctrl-T
Sir i already tried that it said there is a missing (}) i tried putting it everywhere nothing still happened
It also tells you WHERE the problem is and if you post the COMPLETE error message we will know that useful information too.
Steve
Hi, @sarashina
Welcome to the forum.
Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
If you press CTRL - T in the IDE before posting, it will indent your code to make it easier to read.
Thanks... Tom...
im sorry for the trouble sir is what i did correct ? umm Ctrl+T is auto format right ?
Hi, @sarashina
Yes it is auto format, it will make your code easier to read and find any formatting bugs.
ALSO
In the IDE select "Edit" then "Copy for Forum", this will copy your code to the clipboard with the needed extra text so when you paste into your post, it will be formatted so it can be easily read in the forum.
Thanks.. Tom..
thanks sir i finally fixed how it looks hopefully someone can help me now fixing the program
Hi,
What model Arduino are you using?
Tom...
Arduino uno R3
Appears one too many at line 70.
Also problem with speed undeclared.
how do i declare the speed ?
Maybe like this......
Already have that
Hi,
Can you post your fixed code please, so we can help you further?
You are not using motorspeed as your speed variable.
void setSpeedButton() {
lowSWState = digitalRead(lowSWPin);
delay(1);
if (lowSWState == HIGH) {
speed = speed - motorValue;
if (speed < 0) {
speed = 0;
}
}
highSWState = digitalRead(highSWPin);
delay(1);
if (highSWState == HIGH) {
speed = speed + motorValue;
if (speed > 255) {
speed = 255;
}
}
analogWrite(enablePin1, speed);
analogWrite(enablePin2, speed);
}
int speed=0;
I think is what you need.
Tom...
Thanks.. Tom....
const int lowSWPin=6;
const int highSWPin=11;
const int controlPin1=3;
const int controlPin2=2;
const int controlPin3=4;
const int controlPin4=5;
const int enablePin1=9;
const int enablePin2=10;
const int onOffSwitchStateSWPin = 8;
const int potPin=A0;
int lowSWState=0;
int highSWState=0;
int motorEnabled=0;
int potentiometerVal=0;
int speed =0;
int motorValue =0;
int onOffSWState=0;
int previousOnOffSWState=0;
void setup(){
pinMode(onOffSwitchStateSWPin,INPUT);
pinMode(lowSWPin,INPUT);
pinMode(highSWPin,INPUT);
pinMode(controlPin1,OUTPUT);
pinMode(controlPin2,OUTPUT);
pinMode(controlPin3,OUTPUT);
pinMode(controlPin4,OUTPUT);
pinMode(enablePin1,OUTPUT);
pinMode(enablePin2,OUTPUT);
digitalWrite(enablePin1,HIGH);
digitalWrite(enablePin2,HIGH);
}
void loop(){
potentiometerVal = analogRead(potPin)/4;
onOffSWState = digitalRead(onOffSwitchStateSWPin);
delay(1);
if(onOffSWState!=previousOnOffSWState){
if(onOffSWState==HIGH){
motorEnabled =!motorEnabled;
}
}
if(potentiometerVal >= 127){
digitalWrite(controlPin1,HIGH);
digitalWrite(controlPin3,HIGH);
}
else{
digitalWrite(controlPin1,LOW);
digitalWrite(controlPin3,LOW);
}
if(potentiometerVal <= 127){
digitalWrite(controlPin2,HIGH);
digitalWrite(controlPin4,HIGH);
}
else{
digitalWrite(controlPin2,LOW);
digitalWrite(controlPin4,LOW);
}
if(motorEnabled == 1) {
analogWrite(enablePin1, motorEnabled);
analogWrite(enablePin2, motorEnabled);
}
else {
analogWrite(enablePin1,0);
analogWrite(enablePin2,0);
}
previousOnOffSWState = onOffSWState;
}
}
void setSpeedButton1){
while(1){
lowSWState=digitalRead(lowSWPin);
highSWState=digitalRead(highSWPin);
if(lowSWState==HIGH){
speed=speed - motorValue;
if(speed < 0){
speed = 0;
}
}
if(highSWState==HIGH){
speed=speed + motorValue;
if(speed > 255){
speed = 255;
}
}
analogWrite(enablePin1,speed);
analogWrite(enablePin2,speed);
}
}
There it is still not working
Hi,
- Can you please post a copy of the circuit diagram?
- Can you please post a picture of your project?
- Can you please post links to specs/data of.
- Your motor.
- Your motor driver
Do you have a DMM?
Thaanks.. Tom..
Hi,
It will do for the moment, but is not a true circuit diagram, its what is called a Fritzy and is just a picture of components and tangle of coloured wires.
A proper hand drawn diagram with parts and pin labels would be better.
What are you using to power the motors?
Pin 16 of the 293 should go to the UNO 5v pin, not the motor power supply.
Tom...