Hi Dave
I would be very interested in seeing the sketches if you don't mind!!
Wes
Wes,
Here are the transmitter and receiver sketches. In this example, two pots are connected to the transmitter, the receiver has two LEDs. The pots will dim the leds though the radio link.
Note: I used a MEGA on the receiver. If you use an Uno, you will need to change the output pins to PWM pins on the Uno.
// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
//
// Mod: Two Sensor input (pot on A0 & A1) sent to control PWS on reciever
// Circuit: Transmitter input on pin 12, LED on pin 13 (w/330 ohm resistor),
// pot 1 center output pin to pin A0, pot 2 center output pin to pin A1.
// Mod by: Dave Gundlach, June 2013
#include <VirtualWire.h>
int sensor1Data; // Data varable for pot 1
int sensor2Data; // Data varable for pot 2
char sensor1Char[4]; // Charactor array for pot 1
char sensor2Char[4]; // Charactor array for pot 2
char sensor12Char[7]; // Combined array for pot 1 & 2
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
pinMode(13, OUTPUT); // LED output
pinMode(A0, INPUT); // Sensor input (pot 1)
pinMode(A1, INPUT); // Sensor input (pot 2)
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}
void loop()
{
sensor1Data= analogRead(A0); // read sensor (pot 1)
sensor2Data= analogRead(A1); // read sensor (pot 2)
// Note: Needed values from 0-255, added 100 to values so there are
// always 3 charactors
sensor1Data = map(sensor1Data, 0, 1023, 100, 355); // map sensor output
sensor2Data = map(sensor2Data, 0, 1023, 100, 355); // map sensor output
itoa(sensor1Data, sensor1Char, 10); // convert sensor data to char
itoa(sensor2Data, sensor2Char, 10); // convert sensor data to char
for (int i=0; i<3; i++)
{
sensor12Char[i] = sensor1Char[i]; // put sensor 1 caractors in
}
for (int i=0; i<3; i++)
{
sensor12Char[i+3] = sensor2Char[i]; // put sensor 2 caractors in
}
sensor12Char[6] = '\0';
Serial.println(sensor12Char); // debug check
digitalWrite(13, HIGH); // Flash an LED to show transmitting
vw_send((uint8_t *)sensor12Char, strlen(sensor12Char));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, LOW); // turn off LED
delay(150); // small delay for smooth control
}
// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
//
// MOD: Two Sensor input from transmitter to control PWS on Mega pins 2 & 3
// Circuit: Reciever output to Pin 11, LEDs (w/330 ohm resistors) on PWM pins 2 & 3
// Mod by Dave Gundlach, June 2013
#include <VirtualWire.h>
long timerLED; // timer for LED on
int sensor1Data; // Data variable for pot 1
int sensor2Data; // Data variable for pot 2
char sensor1Char[4]; // Charactor array for pot 1
char sensor2Char[4]; // Charactor array for pot 2
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
pinMode(13, OUTPUT); // Recieve LED
pinMode(2, OUTPUT); // PWM output from pot 1
pinMode(3, OUTPUT); // PWM output from pot 2
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (millis() >= timerLED){ // check if LED timer has expired
digitalWrite(13, LOW); // turn LED off
}
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(13, HIGH); // Flash a light to show received good message
timerLED = millis()+100; // set LED timer
// Message with a good checksum received, dump it.
Serial.print("Got: "); // Debug message
for (i = 0; i < 3; i++) // convert buffer into char
{
sensor1Char[i] = char(buf[i]); // pot 1 value
}
// Transmitter added 100 so each value will will always have 3 charactors
sensor1Data = atoi(sensor1Char)-100; // convert to integer and subtract 100
for (i = 0; i < 3; i++)
{
sensor2Char[i] = char(buf[i+3]); // pot 2 value
}
sensor2Data = atoi(sensor2Char)-100; // convert to integer and subract 100
analogWrite(2, sensor1Data); // PWM LED for pot 1 value (mega)
analogWrite(3, sensor2Data); // PWM LED for pot 2 value (mega)
Serial.print(sensor1Data); // Debug
Serial.print(" ");
Serial.print(sensor2Data);
Serial.println("");
//digitalWrite(13, LOW);
for (i=0; i<4; i++)
{
sensor1Char[i] = 0; // clear array
sensor2Char[i] = 0; // clear array
}
}
}
Dave