Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,16,2);
- // RemoteXY select connection mode and include library
- #define REMOTEXY_MODE__HARDSERIAL
- #include <RemoteXY.h>
- // RemoteXY connection settings
- #define REMOTEXY_SERIAL Serial
- #define REMOTEXY_SERIAL_SPEED 9600
- // RemoteXY configurate
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] =
- { 255,6,0,0,0,112,0,10,120,0,
- 2,1,2,2,18,9,1,26,31,31,
- 78,121,97,108,97,104,0,77,97,116,
- 105,0,5,20,69,32,30,30,120,24,
- 31,3,130,82,2,16,9,1,26,2,
- 1,2,50,18,9,120,26,31,31,76,
- 97,109,112,117,32,110,121,97,108,97,
- 104,0,76,97,109,112,117,32,109,97,
- 116,105,0,2,1,2,36,18,9,120,
- 26,31,31,83,105,114,101,110,101,32,
- 110,121,97,108,97,104,0,83,105,114,
- 101,110,101,32,109,97,116,105,0 };
- // this structure defines all the variables and events of your control interface
- struct {
- // input variables
- uint8_t saklar; // =1 if switch ON and =0 if OFF
- int8_t joystick_1_x; // =-100..100 x-coordinate joystick position
- int8_t joystick_1_y; // =-100..100 y-coordinate joystick position
- uint8_t select_1; // =0 if select position A, =1 if position B, =2 if position C, ...
- uint8_t lampu; // =1 if switch ON and =0 if OFF
- uint8_t sirene; // =1 if switch ON and =0 if OFF
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- int Signal;
- int Threshold = 550;
- int count = 0;
- int ledState1 = LOW;
- unsigned long previousMillis1 = 0;
- unsigned long previousMillis2 = 0;
- unsigned long previousMillis3 = 0;
- const long interval1 = 750;
- const long interval2 = 3000;
- const long interval3 = 1000;
- /* defined the right motor control pins */
- #define PIN_MOTOR_RIGHT_UP 7
- #define PIN_MOTOR_RIGHT_DN 6
- #define PIN_MOTOR_RIGHT_SPEED 10
- /* defined the left motor control pins */
- #define PIN_MOTOR_LEFT_UP 5
- #define PIN_MOTOR_LEFT_DN 4
- #define PIN_MOTOR_LEFT_SPEED 9
- #define PIN_SAKLAR 13
- #define PIN_LAMPU 11
- #define PIN_SIRENE 12
- /* defined two arrays with a list of pins for each motor */
- unsigned char RightMotor[3] =
- {PIN_MOTOR_RIGHT_UP, PIN_MOTOR_RIGHT_DN, PIN_MOTOR_RIGHT_SPEED};
- unsigned char LeftMotor[3] =
- {PIN_MOTOR_LEFT_UP, PIN_MOTOR_LEFT_DN, PIN_MOTOR_LEFT_SPEED};
- /*
- speed control of the motor
- motor - pointer to an array of pins
- v - motor speed can be set from -100 to 100
- */
- void Wheel (unsigned char * motor, int v)
- {
- if (v>100) v=100;
- if (v<-100) v=-100;
- if (v>0) {
- digitalWrite(motor[0], HIGH);
- digitalWrite(motor[1], LOW);
- analogWrite(motor[2], v*2.55);
- }
- else if (v<0) {
- digitalWrite(motor[0], LOW);
- digitalWrite(motor[1], HIGH);
- analogWrite(motor[2], (-v)*2.55);
- }
- else {
- digitalWrite(motor[0], LOW);
- digitalWrite(motor[1], LOW);
- analogWrite(motor[2], 0);
- }
- }
- byte Eyes1[8] = {
- B11111,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B11111
- };
- byte Eyes2[8] = {
- B11111,
- B00000,
- B00000,
- B11111,
- B11111,
- B00000,
- B00000,
- B11111
- };
- byte Eyes3[8] = {
- B11111,
- B00001,
- B00001,
- B00001,
- B00001,
- B00001,
- B00001,
- B11111
- };
- byte Sleep1[8] = {
- B00000,
- B00000,
- B00000,
- B11111,
- B11111,
- B00000,
- B00000,
- B00000
- };
- byte senyum1[8] = {
- B00000,
- B00000,
- B00001,
- B00011,
- B00110,
- B01100,
- B11000,
- B10000
- };
- byte senyum2[8] = {
- B00000,
- B00000,
- B11111,
- B11111,
- B00000,
- B00000,
- B00000,
- B00000
- };
- byte senyum3[8] = {
- B00000,
- B00000,
- B10000,
- B11000,
- B01100,
- B00110,
- B00011,
- B00001
- };
- byte senyummouth1[8] = {
- B10000,
- B11000,
- B01100,
- B00110,
- B00011,
- B00001,
- B00000,
- B00000
- };
- byte senyummouth2[8] = {
- B00000,
- B00000,
- B00000,
- B00000,
- B11111,
- B11111,
- B00000,
- B00000
- };
- byte senyummouth3[8] = {
- B00001,
- B00011,
- B00110,
- B01100,
- B11000,
- B10000,
- B00000,
- B00000
- };
- void setup() {
- lcd.begin();
- lcd.setBacklight(HIGH);
- pinMode (PIN_MOTOR_RIGHT_UP, OUTPUT);
- pinMode (PIN_MOTOR_RIGHT_DN, OUTPUT);
- pinMode (PIN_MOTOR_LEFT_UP, OUTPUT);
- pinMode (PIN_MOTOR_LEFT_DN, OUTPUT);
- pinMode (PIN_SAKLAR, OUTPUT);
- pinMode (PIN_LAMPU, OUTPUT);
- pinMode (PIN_SIRENE, OUTPUT);
- /* initialization module RemoteXY */
- RemoteXY_Init ();
- lcd.createChar(0, Eyes1);
- lcd.createChar(1, Eyes2);
- lcd.createChar(2, Eyes3);
- lcd.createChar(3, Sleep1);
- lcd.createChar(4, senyum1);
- lcd.createChar(5, senyum2);
- lcd.createChar(6, senyum3);
- lcd.createChar(7, senyummouth1);
- lcd.createChar(8, senyummouth2);
- lcd.createChar(9, senyummouth3);
- lcd.clear();
- }
- void loop() {
- unsigned long currentMillis = millis();
- RemoteXY_Handler ();
- if (RemoteXY.saklar!=0) {
- /* manage the right motor */
- Wheel (RightMotor, RemoteXY.joystick_1_y - RemoteXY.joystick_1_x);
- /* manage the left motor */
- Wheel (LeftMotor, RemoteXY.joystick_1_y + RemoteXY.joystick_1_x);
- lcd.setBacklight(HIGH);
- digitalWrite(PIN_SAKLAR, HIGH);
- if (RemoteXY.lampu!=0) {
- digitalWrite(PIN_LAMPU, HIGH);
- }
- else {
- digitalWrite(PIN_LAMPU, LOW);
- }
- if (RemoteXY.sirene!=0) {
- digitalWrite(PIN_SIRENE, HIGH);
- }
- else
- {
- digitalWrite(PIN_SIRENE, LOW);
- }
- if (RemoteXY.select_1==0) {
- if (currentMillis - previousMillis1 >= interval1) {
- previousMillis1 = currentMillis;
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.write(byte(0));
- lcd.setCursor(1,0);
- lcd.write(byte(1));
- lcd.setCursor(2,0);
- lcd.write(byte(1));
- lcd.setCursor(3,0);
- lcd.write(byte(2));
- lcd.setCursor(6,1);
- lcd.write(byte(3));
- lcd.setCursor(7,1);
- lcd.write(byte(3));
- lcd.setCursor(8,1);
- lcd.write(byte(3));
- lcd.setCursor(9,1);
- lcd.write(byte(3));
- lcd.setCursor(12,0);
- lcd.write(byte(0));
- lcd.setCursor(13,0);
- lcd.write(byte(1));
- lcd.setCursor(14,0);
- lcd.write(byte(1));
- lcd.setCursor(15,0);
- lcd.write(byte(2));
- }
- else if (currentMillis - previousMillis2 >= interval2) {
- previousMillis2 = currentMillis;
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.write(byte(3));
- lcd.setCursor(1,0);
- lcd.write(byte(3));
- lcd.setCursor(2,0);
- lcd.write(byte(3));
- lcd.setCursor(3,0);
- lcd.write(byte(3));
- lcd.setCursor(6,1);
- lcd.write(byte(3));
- lcd.setCursor(7,1);
- lcd.write(byte(3));
- lcd.setCursor(8,1);
- lcd.write(byte(3));
- lcd.setCursor(9,1);
- lcd.write(byte(3));
- lcd.setCursor(12,0);
- lcd.write(byte(3));
- lcd.setCursor(13,0);
- lcd.write(byte(3));
- lcd.setCursor(14,0);
- lcd.write(byte(3));
- lcd.setCursor(15,0);
- lcd.write(byte(3));
- }
- }
- else if (RemoteXY.select_1==1) {
- if (currentMillis - previousMillis3 >= interval3) {
- previousMillis3 = currentMillis;
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.write(byte(4));
- lcd.setCursor(1,0);
- lcd.write(byte(5));
- lcd.setCursor(2,0);
- lcd.write(byte(5));
- lcd.setCursor(3,0);
- lcd.write(byte(6));
- lcd.setCursor(6,1);
- lcd.write(byte(7));
- lcd.setCursor(7,1);
- lcd.write(byte(8));
- lcd.setCursor(8,1);
- lcd.write(byte(8));
- lcd.setCursor(9,1);
- lcd.write(byte(9));
- lcd.setCursor(12,0);
- lcd.write(byte(4));
- lcd.setCursor(13,0);
- lcd.write(byte(5));
- lcd.setCursor(14,0);
- lcd.write(byte(5));
- lcd.setCursor(15,0);
- lcd.write(byte(6));
- }
- }
- }
- else {
- lcd.setBacklight(LOW);
- digitalWrite(PIN_SAKLAR, LOW);
- digitalWrite(PIN_LAMPU, LOW);
- digitalWrite(PIN_SIRENE, LOW);
- lcd.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement