First:
#include "CytronMotorDriver.h"
// Configure the motor driver.
CytronMD motor1(PWM_DIR, 3, 4); // PWM 1 = Pin 3, DIR 1 = Pin 4.
CytronMD motor2(PWM_DIR, 9, 10); // PWM 2 = Pin 9, DIR 2 = Pin 10.
// The setup routine runs once when you press reset.
void setup() {
}
// The loop routine runs over and over again forever.
void loop() {
motor1.setSpeed(128); // Motor 1 runs forward at 50% speed.
motor2.setSpeed(-128); // Motor 2 runs backward at 50% speed.
delay(1000);
motor1.setSpeed(255); // Motor 1 runs forward at full speed.
motor2.setSpeed(-255); // Motor 2 runs backward at full speed.
delay(1000);
motor1.setSpeed(0); // Motor 1 stops.
motor2.setSpeed(0); // Motor 2 stops.
delay(1000);
motor1.setSpeed(-128); // Motor 1 runs backward at 50% speed.
motor2.setSpeed(128); // Motor 2 runs forward at 50% speed.
delay(1000);
motor1.setSpeed(-255); // Motor 1 runs backward at full speed.
motor2.setSpeed(255); // Motor 2 runs forward at full speed.
delay(1000);
motor1.setSpeed(0); // Motor 1 stops.
motor2.setSpeed(0); // Motor 2 stops.
delay(1000);
}
second sketche
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(8,9,4,5,6,7);
// make some custom characters:
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};
byte frownie[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b00000,
0b01110,
0b10001
};
byte armsDown[8] = {
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};
byte armsUp[8] = {
0b00100,
0b01010,
0b00100,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010
};
void setup() {
// initialize LCD and set up the number of columns and rows:
lcd.begin(16, 2);
// create a new character
lcd.createChar(0, heart);
// create a new character
lcd.createChar(1, smiley);
// create a new character
lcd.createChar(2, frownie);
// create a new character
lcd.createChar(3, armsDown);
// create a new character
lcd.createChar(4, armsUp);
// set the cursor to the top left
lcd.setCursor(0, 0);
// Print a message to the lcd.
lcd.print(" NELMOW");
lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
lcd.print("NELSONS");
lcd.write((byte)1);
}
void loop() {
// read the potentiometer on A0:
int sensorReading = analogRead(A0);
// map the result to 200 - 1000:
int delayTime = map(sensorReading, 0, 1023, 200, 1000);
// set the cursor to the bottom row, 5th position:
lcd.setCursor(4, 1);
// draw the little man, arms down:
lcd.write(3);
delay(delayTime);
lcd.setCursor(4, 1);
// draw him arms up:
lcd.write(4);
delay(delayTime);
}
3rd skecthe
would be to ad 4Ir ( i, e ) 2 up front, 2 in the back for edge and ultrasonic sensors 1 in the back, 1 front, and 1 on both side. I think that I can only have a code that works for 1 IR and 1 ULtrasonic, then connect the rest in parallel to ad up more. Maybe!`Preformatted text`