/*
* RF24L01_Transmitter.ino by Tucker Ballantyne on 5/5/2016
*
* I downloaded the RF24.h library from:
* https://arduino-info.wikispaces.com/nRF24L01-RF24-Examples
* The RF24L01 must use Teensy SPI port pins
* RF24 wired to teensy as:
* Teensy RF24
* pin 13 SCK
* pin 12 MISO
* pin 11 MOSI
* pin 10 CSN
* pin 9 CE
* 3.3V VCC 3.3 volts is VERY important
* GND GND
*
* ?
* Copyright Tucker Ballantyne 2016. All Rights Reserved.
* No part of these contents may be reproduced, copied, modified or adapted,
* without the prior written consent of the author, unless when used for
* educational and non-profit purposes.?
*/
#include <SPI.h>
#include "RF24.h"
#include <Servo.h>
RF24 radio(9, 10); // Set up nRF24L01 radio on SPI bus plus pins 9 & 10
const uint64_t writing_pipe = 0xF0F0F0F0E2LL;
const uint64_t reading_pipe = 0xF0F0F0F0E2LL;
//********************************************************
// Servo Setup
//********************************************************
Servo LServo;
Servo RServo;
const int leftServo = 2;
const int rightServo = 3;
const int left_forward_fast = 2000; // CCW Fast
const int left_forward_slow = 1650;
const int left_stop = 1500; // Center position
const int left_backward_slow = 1350;
const int left_backward_fast = 1000; // CW Fast
const int right_forward_fast = 1100; // CW Fast
const int right_forward_slow = 1350;
const int right_stop = 1500; // Center position
const int right_backward_slow = 1625;
const int right_backward_fast = 2000; // CCW Fast
//********************************************************
// Setup
//********************************************************
void setup()
{
Serial.begin(9600);
radio.begin(); //starts the radio
radio.setRetries(1, 0); //after failing to send, the delay and number of retries
radio.setAutoAck(false);
radio.setCRCLength(RF24_CRC_16);
radio.setPayloadSize(sizeof(int)); //maximum size of the data that can be sent
radio.openWritingPipe(writing_pipe);//tells the radio what signal to send data over
pinMode(A9, INPUT_PULLUP); //Place a photoresistor on A9 to ground
pinMode(A4, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
Serial.begin(9600);
LServo.attach(2);
RServo.attach(3);
}
//********************************************************
// Main Loop
//********************************************************
void loop()
{
int sens1 = analogRead(A2);
int sens2 = analogRead(A3); //change analog pin-done
int sens3 = analogRead(A4);
Serial.print("Sending ");
int sensTot = sens1 * 1000000 + sens2 * 1000 + sens3;
Serial.println("sens1 = " + (String)sens1 + "sens2 = " + (String)sens2 + "sens3 = " + (String)sens3);
radio.startWrite(& sensTot, sizeof(int));
}