Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in menu_set_active_trail() (line 2405 of /home/dmirpuri/public_html/mtec2250/includes/menu.inc).

Code Plan

Explanation

The user will be able to push one of the three buttons that are available on the pendant depending on how they are feeling at the moment. Each button will send a different message to the screen of the bracelet.

 

Components

  • 315Mhz RF Transmitter
  • 315Mhz Receiver
  • 3x Push Buttons
  • 3x 10k ohm resistors

 

Pseudocode

​I am using the RadioHead Library, download available here

Using the RH_ASK Class Driver, it works with a wide range of transmitters and receivers.

 

Push Buttons

  • Define all 3 buttons
  • Set pinMode of all 3 buttons to INPUT
  • Read button
  • When button clicked, it sends a message

Using if statements:

  • Message for Button 1: "I feel sick!!"
  • Message for Button 2: "I need to talk to you."
  • Message for Button 3: "HELP!!"

Transmitter

It first initiates the driver

The boolean RH_ASK send takes these parameters: (const uint8_t * data, uint8_t len)

Parameters

[in] data Array of data to be sent 
[in] len Number of bytes of data to send (> 0) 

Returns: true if the message length was valid and it was correctly queued for transmit

Then using the waitPacketSent(), that waits until previous transmit packet is finished being transmitted.

This will then load the message into the transmitter and start it.

Code plan for the transmitter:

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module

// transmitter pin
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver;
//Connect data to pin 12

define all three buttons to 2,4, and 7
set integer currentState to 0

Setup:

Serial.begin(4800);      // Debugging only
set each pinMode of the button to INPUT
 

Loop:

initiate 3 toggleState to read the input of each button

if the toggleState is HIGH, then print string message

     send the message to the receiver, this is where it uses one of the functions from the RadioHead Library
     add a delay of 100-200
  
set each toggleState with different messages

if toggleState is LOW, add one to currentState

 

Receiver

The boolean RH_ASK recv takes these parameters: (uint8_t * buf, uint8_t * len)

Parameters

[in] buf Location to copy the received message 
[in,out] len Pointer to available space in buf. Set to the actual number of octets copied. 

Returns: true if a valid message was copied to buf

This turns the receiver on. If there is a valid message, it will copy it to buf and return true else return false. If a message is copied, *len is set to the length.

Code plan for the receiver:

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver;  //Connect data to pin 11

Setup:

Serial.begin(4800);    // Debugging only

Loop:
check string message length

receives the message from the transmitter using the library
parse the string message

return the parsed message

print the message