matpi / EmbeddedSystemsUTU

This repository concerns the course KSA4 Embedded Systems (craft, design and technology education) in the University of Turku, Department of Teacher Education, Rauma Unit in the academic year 2014
4 stars 5 forks source link

Juomantilauslaitteen koodit #44

Open saloantt opened 9 years ago

saloantt commented 9 years ago

Vastaanottimen ja lähettimen koodit, sekä video.

saloantt commented 9 years ago

VASTAANOTIN /* YourDuinoStarter Example: nRF24L01 Receive Joystick values

/-----( Import needed libraries )-----/

include

include

include

/-----( Declare Constants and Pin Numbers )-----/

define CE_PIN 9

define CSN_PIN 10

define LED 2

define LED1 4

define LED2 7

define LED3 6

// 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);

} } } } }

saloantt commented 9 years ago

LÄHETIN

/* YourDuinoStarter Example: nRF24L01 Transmit Joystick values

/-----( Import needed libraries )-----/

include

include

include

/-----( Declare Constants and Pin Numbers )-----/

define CE_PIN 9

define CSN_PIN 10

define BUTTON1 5

define BUTTON2 6

define BUTTON3 7

define BUTTON4 8

// 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 )******

saloantt commented 9 years ago

Videon linkki

https://www.youtube.com/watch?v=-b6Kry5fFVQ&feature=youtu.be