Open saloantt opened 9 years ago
VASTAANOTIN /* YourDuinoStarter Example: nRF24L01 Receive Joystick values
V1.00 11/26/13 Based on examples at http://www.bajdi.com/ Questions: terry@yourduino.com */
//MUOKATTU OMAAN PROJEKTIIN 24.4.2015 https://github.com/matpi/EmbeddedSystems2014/issues/44
/-----( Import needed libraries )-----/
/-----( Declare Constants and Pin Numbers )-----/
// NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/-----( Declare objects )-----/ RF24 radio(CE_PIN, CSNPIN); // Create a Radio /-----( Declare Variables )-----_/ int joystick[4]; // 2 element array holding Joystick readings //muokattu6 int val = 1; int val1 = 1; int val2 = 1; int val3 = 1; int old_val = 1; int old_val1 = 1; int old_val2 = 1; int old_val3 = 1; int state = 0; int state1 = 0; int state2 = 0; int state3 = 0; void setup() /\ SETUP: RUNS ONCE **/ { pinMode(LED, OUTPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); Serial.begin(9600); delay(1000); Serial.println("Nrf24L01 Receiver Starting"); radio.begin(); radio.openReadingPipe(1,pipe); radio.startListening();; }//--(end setup )---
void loop() /\ LOOP: RUNS CONSTANTLY **/
{
if ( radio.available() ){
// Fetch the data payload
radio.read( joystick, sizeof(joystick));
Serial.print("alas = ");
Serial.print(joystick[0]);
Serial.print("yles = ");
Serial.print(joystick[1]);
Serial.print("MAGI = ");
Serial.println(joystick[2]);
Serial.print("KOSSU = ");
Serial.print(joystick[3]);
}
else
{
Serial.println("No radio available");
}
val = digitalRead (joystick[0]); val1 = digitalRead (joystick[1]); val2 = digitalRead (joystick[2]); val3 = digitalRead (joystick[3]);
if((val1 == 1) && (old_val1 == 0)) { state1 = 1 - state1; delay(10); } old_val1 = val1; if (state1 == 1) { digitalWrite (LED1, HIGH); }else{ digitalWrite(LED1, LOW);
if((val == 1) && (old_val == 0)) { state = 1 - state; delay(10); } old_val = val; if (state == 1) { digitalWrite (LED, HIGH); }else{ digitalWrite(LED, LOW);
if((val2 == 1) && (old_val2 == 0)) { state2 = 1 - state2; delay(10); } old_val2 = val2; if (state2 == 1) { digitalWrite (LED2, HIGH); }else{ digitalWrite(LED2, LOW);
if((val3 == 1) && (old_val3 == 0)) {
state3 = 1 - state3; delay(10); } old_val3 = val3; if (state3 == 1) { digitalWrite (LED3, HIGH); }else{ digitalWrite(LED3, LOW);
} } } } }
LÄHETIN
/* YourDuinoStarter Example: nRF24L01 Transmit Joystick values
Analog Joystick or two 10K potentiometers: GND to Arduino GND VCC to Arduino +5V X Pot to Arduino A0 Y Pot to Arduino A1 muokattu Z Pot to A2 B Pot to A3
V1.00 11/26/13 Based on examples at http://www.bajdi.com/ Questions: terry@yourduino.com */
//MUOKATTU OMAAN PROJEKTIIN 24.4.2015 https://github.com/matpi/EmbeddedSystems2014/issues/44
/-----( Import needed libraries )-----/
/-----( Declare Constants and Pin Numbers )-----/
// NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe int val1 = 1; int val2 = 1; int val3 = 1; int val4 = 1;
/-----( Declare objects )-----/ RF24 radio(CE_PIN, CSNPIN); // Create a Radio /-----( Declare Variables )-----_/ int joystick[4]; // 2 element array holding Joystick readings, muokattu 6
void setup() /\ SETUP: RUNS ONCE **/ {
Serial.begin(9600); radio.begin(); radio.openWritingPipe(pipe);
pinMode (BUTTON1, INPUT_PULLUP); pinMode (BUTTON2, INPUT_PULLUP); pinMode (BUTTON3, INPUT_PULLUP); pinMode (BUTTON4, INPUT_PULLUP);
}//--(end setup )---
void loop() /\ LOOP: RUNS CONSTANTLY **/ { val1 = digitalRead(5); val2 = digitalRead(6); val3 = digitalRead(7); val4 = digitalRead(8);
joystick[0] = digitalRead(5); joystick[1] = digitalRead(6); joystick[2] = digitalRead(7); joystick[3] = digitalRead(8); Serial.println(joystick[0]); Serial.println(joystick[1]); Serial.println("eka"); Serial.println(joystick[2]); Serial.println(joystick[3]); Serial.println("toka");
radio.write( joystick, sizeof(joystick));
}//--(end main loop )---
/-----( Declare User-written Functions )-----/
//NONE //****( THE END )******
Vastaanottimen ja lähettimen koodit, sekä video.