You are on page 1of 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