2019/07/20

MakerRemote Mower: Sketch For Radio Frequency Remote Controlling A Mower Or Car

The sketch is used to control the direction the radio frequency controlled mower or car. The message sent can be monitored by SimpleReceiveLCD on May. 11, 2014.

Sketch

//File Name: MakerRemoteMowerDirectionSendOneTimeV10
// Modified by Befun Hung on Jul. 16, 2019
// Blink led on time after sending direction character (one character)
// The direction character may be one of 0-9, * and #
// The direction character is designed as
// 2, forward, both left and right wheel forward
// 4, left, right wheel forward and left wheel backward
// 6, right, left wheel forward and right wheel backward
// 8, backward, both left and right wheel backward
// 1, forward left, right wheel forward and left wheel stop
// 3, forward right, left wheel forward and right wheel stop
// 7, backward left, right wheel backward and left wheel stop
// 9, backward right, left wheel backward and right wheel stop
// 5, stop both left and right wheels
// 0, do nothing
// *, turn on mower motor
// #, turn off mower motor
// The sketch is tested and comfirmed with only one direction character received
//
// Modified by Befun Hung on Oct. 28, 2014 
// Blink led after sending message to notice user 5 times 


#include <Keypad.h>
#include <VirtualWire.h>


#define maxLength 1  // maxLength 3 changed to 1


const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {5, 4, 3, 2};
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {8, 7, 6};    // connect to the column pinouts of the keypad
char keyins[maxLength+1] = "";
int i=0, j=0, sendTimes=1;         // sendTimes 5 changed to 1
int led=13;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  Serial.begin(9600);
  // Initialize the IO and ISR
  vw_setup(2000); // Bits per sec
  Serial.println("Ready!");
  pinMode(led, OUTPUT);
}
 
void loop() {
    char key = keypad.getKey();
    if (key) {
      Serial.print(key);
      keyins[i] = key;
      i++;
      if (i == maxLength) {
        for (j=0;j<sendTimes;j++) {
          Serial.println();
          send(keyins);
          digitalWrite(led, HIGH);
          delay(20);
          digitalWrite(led, LOW);
          delay(20);
        }
        i = 0;
      }
    }
}


void send(char *message)
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // Wait until the whole message is gone
}

No comments:

Post a Comment