Skip to content

Instantly share code, notes, and snippets.

@0xff07
Last active January 19, 2018 11:34
Show Gist options
  • Save 0xff07/d84360014d49352aa2537414422bb8cc to your computer and use it in GitHub Desktop.
Save 0xff07/d84360014d49352aa2537414422bb8cc to your computer and use it in GitHub Desktop.
Receiver part for 2018 Winer Camp "Vessels" project
#include<SPI.h>
#include<Servo.h>
#include "RF24.h"
/* Pins for servo motor */
#define PIN_SERVO 6
Servo s;
/* Pins for nrf25l01 as receiver*/
#define PIN_CE 7
#define PIN_CSN 8
#define PIPE_ADDRESS 0xE8E8F0F0E1LL
RF24 rf24(PIN_CE, PIN_CSN);
/* Space to store received data */
int msg[2] = {90, 0};
void setup() {
/* Serial port setting */
Serial.begin(9600);
/* Servo motor setting */
s.attach(PIN_SERVO);
/* nRFL01 sensor setting */
rf24.begin();
rf24.setPALevel(RF24_PA_MIN);
rf24.openReadingPipe(1, PIPE_ADDRESS);
rf24.startListening();
}
void dump() {
Serial.print("msg[0]: ");
Serial.print(msg[0]);
Serial.print("\t msg[1]: ");
Serial.println(msg[1]);
}
void action(int steering, int delta) {
s.write(steering - delta);
delay(100);
s.write(steering + delta);
delay(100);
}
void loop() {
if(rf24.available()) {
rf24.read(&msg, sizeof(int) * 2);
int steering = msg[0];
int delta = msg[1];
}
dump();
action(msg[0], msg[1]);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment