Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define speedofcar 150 //the speed of the motors
- #define rightspeed 5 //this is the pin beside the in1 //must be connected to digital pin with the sine wave
- #define leftspeed 10 //this is the pin beside the in4 //don't need to be written in the void setup
- #define in1 6
- #define in2 7
- #define in3 8
- #define in4 9
- void setup()
- {
- Serial.begin(9600);
- for (int i = 6; i <= 9; i++)
- {
- pinMode(i, OUTPUT);
- }
- }
- void forward();
- {
- digitalWrite(in1,); //according to the battery and motor test
- digitalWrite(in1,);
- digitalWrite(in1,);
- digitalWrite(in1,);
- analogWrite(leftspeed, speedofcar);
- analogWrite(rightspeed, speedofcar);
- }
- void backward();
- {
- digitalWrite(in1,); //according to the battery and motor test
- digitalWrite(in1,);
- digitalWrite(in1,);
- digitalWrite(in1,);
- analogWrite(leftspeed, speedofcar);
- analogWrite(rightspeed, speedofcar);
- }
- void right();
- {
- digitalWrite(in1,); //according to the battery and motor test
- digitalWrite(in1,);
- digitalWrite(in1,);
- digitalWrite(in1,);
- analogWrite(leftspeed, speedofcar);
- analogWrite(rightspeed, speedofcar);
- }
- void left();
- {
- digitalWrite(in1,); //according to the battery and motor test
- digitalWrite(in1,);
- digitalWrite(in1,);
- digitalWrite(in1,);
- analogWrite(leftspeed, speedofcar);
- analogWrite(rightspeed, speedofcar);
- }
- void stopp();
- {
- digitalWrite(in1, 0); //according to the battery and motor test
- digitalWrite(in1, 0);
- digitalWrite(in1, 0);
- digitalWrite(in1, 0);
- analogWrite(leftspeed, speedofcar);
- analogWrite(rightspeed, speedofcar);
- }
- void loop() //bluetooth code
- {
- if (Serial.available() > 0)
- {
- char x = Serial.read();
- switch (x)
- {
- case 'F': forward(); break;
- case 'B': backward(); break;
- case 'R': right(); break;
- case 'L': left(); break;
- case 'S': stopp(); break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement