Question: arduino problem : #include #include #include #include #include Servo servo; / / Servo servo RF 2 4 radio ( 7 , 8 ) ; /
arduino problem :
#include
#include
#include
#include
#include
Servo servo; Servo servo
RF radio; CE CSN
const byte address;
#define LmotorCW
#define LmotorCCW
#define RmotorCW
#define RmotorCCW
#define LmotorSpeed
#define RmotorSpeed
#define waterpump
int waterValue ;
int state ; : idle, : forward, : stop, : pumping, : backward
int value ;
void setup
pinModeLmotorCW OUTPUT;
pinModeLmotorCCW OUTPUT;
pinModeRmotorCW OUTPUT;
pinModeRmotorCCW OUTPUT;
pinModewaterpump OUTPUT;
servo.attach;
analogWriteLmotorSpeed; Motor L ~
analogWriteRmotorSpeed; Motor R ~
setupRadio;
Serial.begin;
Timerinitialize; ms us
TimerattachInterruptwatercheck; Attach the service
void watercheck
receiveData;
Serial.printReceived Water Sensor Value: ;
Serial.printlnwaterValue;
Serial.printmotor : ;
Serial.printlnvalue;
Serial.printState : ;
Serial.printlnstate;
void setupRadio
radio.begin;
radio.openReadingPipe address;
radio.setPALevelRFPAMIN;
radio.startListening;
void go
value ;
servo.writevalue;
delay;
digitalWriteLmotorCW LOW;
digitalWriteLmotorCCW HIGH;
digitalWriteRmotorCW HIGH;
digitalWriteRmotorCCW LOW;
delay;
void stop
digitalWriteLmotorCW LOW;
digitalWriteLmotorCCW LOW;
digitalWriteRmotorCW LOW;
digitalWriteRmotorCCW LOW;
void backward
digitalWriteLmotorCW HIGH;
digitalWriteLmotorCCW LOW;
digitalWriteRmotorCW LOW;
digitalWriteRmotorCCW HIGH;
delay;
void receiveData
if radioavailable
char waterValueStr;
radio.read&waterValueStr, sizeofwaterValueStr;
waterValue atoiwaterValueStr;
void loop
switch state
case : idle
if waterValue
delay;
go;
stop;
delay;
state ;
break;
case : forward
digitalWritewaterpump HIGH;
delay;
state ;
break;
case :
delay;
digitalWritewaterpump LOW;
delay;
state ;
break;
case : stop
backward;
stop;
state;
break;
problem :
If you write servo.write in the setup here, it works well, but if you write servo.write in the loop function, it doesn't work
It works well when operating with the code below, so I don't think it's a final question
What's wrong with the code above?
#include Adding the Servo library
Create a servo object with a Servo service; Servo class
int value ; variable value to adjust the angle
void setup
servo.attach; connect to the servo servo motor pin
Connect to a digital pin that supports PWM with ~ indications
value ;
servo.writevalue; rotate at an angle of value. ex rotate degrees if value is degrees
delay;
void loop
for value ; value ; value
in steps of degree
servo.writevalue;
delay;
for value value; value ; value
servo.writevalue;
delay;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
