guys i cant do my beetle bot 3 in 1 it says 'servopulse' was not declared in this scope

hers the code
No description
19 Replies
nis
nis•8h ago
we don't use PNG for code. We use copied text only. If it can be loaded into the Arduino IDE directly it's not appropriate for a code question. At all. ;)
welden lebe
welden lebeOP•8h ago
oh i will put the code int servoPin = 9; //Define the pins of the steering gear void setup() { pinMode(servoPin, OUTPUT); //steering pin is set to output servopulse(servoPin, 90); //Turn it to 90 degrees delay(300); //delay 0.3S } void loop(){ void servopulse(int pin, int myangle) { //Impulse function int pulsewidth = map(myangle, 0, 180, 500, 2500); //Map Angle to pulse width for (int i = 0; i < 5; i++) { //Output a few more pulses digitalWrite(pin, HIGH);//Set the steering gear interface level to high delayMicroseconds(pulsewidth);//Number of microseconds of delayed pulse width value digitalWrite(pin, LOW);//Lower the level of steering gear interface delay(20 - pulsewidth / 1000);
digitalWrite(pin, LOW);//Lower the level of steering gear interface delay(20 - pulsewidth / 1000); }
} here
nis
nis•8h ago
aight give me a few minutes to reformat it so others can read it. Okay this is not even code yet. You opened void loop() { and then .. you began to define a new function inside the loop.
welden lebe
welden lebeOP•8h ago
so can you fi xit?
Coder_DO_As_Impossible
:PostOnlyInOneChannel:
nis
nis•8h ago
No. You must learn basics. Coding 101 in C++ You do not need to know any details about the Arduino IDE coding environment to fix this coding issue. Nothing. It's a straight up C++ syntax problem. I personally don't handle these issues here, at all. I don't have the personality to walk someone through all that. We do have people who do so, though.
welden lebe
welden lebeOP•8h ago
oh so can i dm them
nis
nis•8h ago
No. They would have to see this post and decide on their own to take an interest in it. Suprisingly, this happens a lot. Some people here are just very generous of time and other resources. ;) It's pretty amazing, actually.
welden lebe
welden lebeOP•8h ago
oh ok šŸ˜„
nis
nis•8h ago
boy scout SNV kind of marked you though with the cross post. ;) which they are supposed to do.
welden lebe
welden lebeOP•8h ago
so its good?
nis
nis•8h ago
Try https://wokwi.com/ while you wait
welden lebe
welden lebeOP•8h ago
the board is a keyestudio nano
nis
nis•8h ago
Nano usually means 328p - that's a part number for an Atmel (company and brand) of chip (the brains). You program it about the same as the Uno R3.
welden lebe
welden lebeOP•8h ago
oh ok
nis
nis•8h ago
aight well I'm going back to what I was doing. Take a look around here as well and see what you can make of what's going on here. ;) Nice to meet you.
welden lebe
welden lebeOP•8h ago
ty so much
nis
nis•8h ago
You are welcome
AnonEngineering
AnonEngineering•5h ago
I have no idea what you are trying to do but as nis said you have syntax errors. This code will at least compile:
c++
int servoPin = 9; //Define the pins of the steering gear

void servopulse(int pin, int myangle) { //Impulse function
int pulsewidth = map(myangle, 0, 180, 500, 2500); //Map Angle to pulse width
for (int i = 0; i < 5; i++) { //Output a few more pulses
digitalWrite(pin, HIGH);//Set the steering gear interface level to high
delayMicroseconds(pulsewidth);//Number of microseconds of delayed pulse width value
digitalWrite(pin, LOW);//Lower the level of steering gear interface
delay(20 - pulsewidth / 1000);
digitalWrite(pin, LOW);//Lower the level of steering gear interface
delay(20 - pulsewidth / 1000);
}
}

void setup() {
pinMode(servoPin, OUTPUT); //steering pin is set to output
servopulse(servoPin, 90); //Turn it to 90 degrees
delay(300); //delay 0.3S
}
void loop() {

}
c++
int servoPin = 9; //Define the pins of the steering gear

void servopulse(int pin, int myangle) { //Impulse function
int pulsewidth = map(myangle, 0, 180, 500, 2500); //Map Angle to pulse width
for (int i = 0; i < 5; i++) { //Output a few more pulses
digitalWrite(pin, HIGH);//Set the steering gear interface level to high
delayMicroseconds(pulsewidth);//Number of microseconds of delayed pulse width value
digitalWrite(pin, LOW);//Lower the level of steering gear interface
delay(20 - pulsewidth / 1000);
digitalWrite(pin, LOW);//Lower the level of steering gear interface
delay(20 - pulsewidth / 1000);
}
}

void setup() {
pinMode(servoPin, OUTPUT); //steering pin is set to output
servopulse(servoPin, 90); //Turn it to 90 degrees
delay(300); //delay 0.3S
}
void loop() {

}

Did you find this page helpful?