This is a Neal, a customer for Adafruit.
I want code for sending a message to the serial monitor through the RFM69 radio when the servo has moved.
It would kind of be like the RadioHead69_RawDemoTXRX_OLED sketch but for servos rather than buttons.
I think would be best to use this code I made.
In my code I commented where the servo starts moving with with "Servo Starts Moving Here" and when the servo stops moving with "Servo Stops Moving Here".
Here is the code I made:
Code: Select all
#include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
#define LED 13// FOR LED
Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2;
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
const int threshold = 0;
int health = 500;
// 6 total sensor readings (from 0 to 5)
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
int pos =0;
int deaths=1;// gonna be number of deaths
void setup()
{
// pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
pinMode(LED, OUTPUT);//FOR LED
Serial.begin(9600);
Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");
// sg90
lcd.begin (20 , 4);
lcd.clear();
Serial.begin(9600);
myservo1.attach(9);
myservo1.write(0);//was 0
myservo2.attach(10);
myservo2.write(45);//was 179
}
void loop()
{
do
{
myservo1.detach();
myservo2.detach();
sensorReading = analogRead(knockSensor);
lcd.setCursor(0, 1);
Serial.println(health);
lcd.println(health);
if (sensorReading > threshold) {
Serial.println("Knock!");
health = health - sensorReading;
Serial.print(sensorReading);
lcd.print(sensorReading);
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading1= analogRead(knockSensor1);
if (sensorReading1 > threshold) {
Serial.println("Knock!");
health = health - sensorReading1;
Serial.print(sensorReading1);
lcd.print(sensorReading1);
int sensorValue = analogRead(A1);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading2= analogRead(knockSensor2);
if (sensorReading2 > threshold) {
Serial.println("Knock!");
health = health - sensorReading2;
Serial.print(sensorReading2);
lcd.print(sensorReading2);
int sensorValue = analogRead(A2);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading3= analogRead(knockSensor3);
if (sensorReading3 > threshold) {
Serial.println("Knock!");
health = health - sensorReading3;
Serial.print(sensorReading3);
lcd.print(sensorReading3);
int sensorValue = analogRead(A3);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading4= analogRead(knockSensor4);
if (sensorReading4 > threshold) {
Serial.println("Knock!");
health = health - sensorReading4;
Serial.print(sensorReading4);
lcd.print(sensorReading4);
int sensorValue = analogRead(A6);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading5= analogRead(knockSensor5);
if (sensorReading5 > threshold) {
Serial.println("Knock!");
health = health - sensorReading5;
Serial.print(sensorReading5);
lcd.print(sensorReading5);
int sensorValue = analogRead(A7);
Serial.println(sensorValue);
delay(1);
}
} while (health > 1);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);//was 2000 // FOR LED IN ARDUINO
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
/*
digitalWrite(LED, HIGH);
delay(2000); //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
*/
myservo1.attach(9);
myservo2.attach(10);
delay(15);
//Servo Starts Moving Here
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
//Servo Stops Moving Here
}
delay(1000);
lcd.setCursor(0, 2);
Serial.println(deaths); //showind number of deaths on the lcd
lcd.println(deaths);
deaths= deaths + 1;// adding deaths
health = 500;
}
This code I made moves a servo after the sensors have been pressed to much.
But I want the it to send a message to the serial monitor through the radio when the servo has moved.
Can you tell me what code is used to send a message to the serial monitor through the radio when the servo has moved?