0% found this document useful (0 votes)
41 views5 pages

Rocker Bogie (2WD. ONLY)

This Arduino code controls a two-wheeled robot (rocking bogie) using two DC motors connected to motor terminals 3 and 4. It defines objects to control each motor and includes functions to move the robot forward, backward, left, and right by controlling the speed and direction of each motor separately. When a command character is received over serial, the appropriate motion function is called. [/SUMMARY]

Uploaded by

Patrick Mariño
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views5 pages

Rocker Bogie (2WD. ONLY)

This Arduino code controls a two-wheeled robot (rocking bogie) using two DC motors connected to motor terminals 3 and 4. It defines objects to control each motor and includes functions to move the robot forward, backward, left, and right by controlling the speed and direction of each motor separately. When a command character is received over serial, the appropriate motion function is called. [/SUMMARY]

Uploaded by

Patrick Mariño
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Rocker Bogie (2WD.

ONLY)
#include <AFMotor.h>

//creates two objects to control the terminal 3 and 4 of motor shield

AF_DCMotor motor1(3);

AF_DCMotor motor2(4);

char command;

void setup() {

Serial.begin(9600); //Set the baud rate to your Bluetooth module.

void loop(){

if(Serial.available() > 0){

command = Serial.read();

Stop(); //initialize with motors stoped

//Change pin mode only if new command is different from previous.

Serial.println(command);

switch(command){

case 'F':

forward();

break;

case 'B':

back();

break;

case 'L':

left();

break;
case 'R':

right();

break; }

}}

void forward() {

motor1.setSpeed(255);

motor1.run(BACKWARD);

motor2.setSpeed(255);

motor2.run(BACKWARD);

void back() {

motor1.setSpeed(255);

motor1.run(FORWARD);

motor2.setSpeed(255);

motor2.run(FORWARD);

void left() {

motor1.setSpeed(255);

motor1.run(BACKWARD);

motor2.setSpeed(0);

motor2.run(RELEASE);

void right() {

motor1.setSpeed(0);

motor1.run(RELEASE);
motor2.setSpeed(255);

motor2.run(BACKWARD);

void Stop() {

motor1.setSpeed(0);

motor2.run(RELEASE);

motor2.setSpeed(0);

motor2.run(RELEASE);

[/code ]

//Created by: Randell L. Mendoza and Patrick D. Mariño of BsCoE-E81


Array Light

int ledPins[]={2,3,4,5,6,7,8,9};

void setup()

for (int i =0; i <8; i++)

pinMode(ledPins[i],OUTPUT);

void loop()

int i = 0;

while (i<7)

digitalWrite(ledPins[i],HIGH);

delay(100);

digitalWrite(ledPins[i],LOW);

i++;

i = 7;
while (i >0)

digitalWrite(ledPins[i],HIGH);

delay(100);

digitalWrite(ledPins[i],LOW);

i--;

//Created by: Randell L. Mendoza and Patrick D. Mariño of BsCoE-E81

You might also like