Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Added processCharacter method #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robnewton
Copy link

Separated buffer building and command parsing from serial port reading.

Separated buffer building and command parsing from serial port reading.
@robnewton
Copy link
Author

Usage is shown below. In my example, I am using VirtualWire to transmit the command wirelessly from a host Arduino connected to the PC to a second receiver Arduino which is not connected to the PC but within wireless range of the first.

#include <VirtualWire.h>
#include <SerialCommand.h>

// Variables 
SerialCommand sCmd;

void setup() {
  // Listen on serial connection for messages from the PC
  Serial.begin(9600); 
  Serial.println("Setup");

  // Setup callbacks for SerialCommand commands
  sCmd.addCommand("P", processCommand);   // Process the command
  sCmd.setDefaultHandler(unrecognized);     // Handler for command that isn't matched

  // Required for DR3100 
  vw_set_ptt_inverted(true);
  vw_set_rx_pin(12);

  //speed of data transfer Kbps - bits per sec 
  vw_setup(4000); 

  // Start the receiver PLL running
  vw_rx_start();
}

void loop(){
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) {
    int i;
    for (i = 0; i < buflen; i++){
      sCmd.processCharacter(char(buf[i]));
    }
  }
}

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant