From 4ea41527f13c2adda36e7222bfe5cded334f8d14 Mon Sep 17 00:00:00 2001 From: Rihards Skuja Date: Sat, 20 Jan 2018 18:47:50 +0200 Subject: [PATCH] Use base staion LED to show found obstacles Transmit 'true' from robot to base station if robot sonar distance is below a set threshold and then turn on ('true' received) or off ('false' received) base station's signal LED. --- base_station/include/main.h | 3 +++ base_station/src/main.c | 18 +++++++++++++++++- robot/include/main.h | 3 +++ robot/src/main.c | 17 +++++++++++++---- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/base_station/include/main.h b/base_station/include/main.h index 29f0d59..0c81e3c 100644 --- a/base_station/include/main.h +++ b/base_station/include/main.h @@ -3,4 +3,7 @@ #include +uint8_t tx_address[5] = {0xD7, 0xD7, 0xD7, 0xD7, 0xD7}; +uint8_t rx_address[5] = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7}; + #endif diff --git a/base_station/src/main.c b/base_station/src/main.c index b1262f4..fbe06ec 100644 --- a/base_station/src/main.c +++ b/base_station/src/main.c @@ -13,11 +13,27 @@ int main(void) { init_leds(); + nrf24_init(); + + nrf24_config(2, 1); // Channel #2, payload: 1 + nrf24_tx_address(tx_address); + nrf24_rx_address(rx_address); // Use green LED as power LED SET(LED_PORT, LED_GREEN_BIT); - while (1) { } + uint8_t data_array[1]; + while (1) { + if (nrf24_dataReady()) { + nrf24_getData(data_array); + + if (data_array[0] == 1) + SET(LED_PORT, LED_BLUE_BIT); + else if (data_array[0] == 0) + CLR(LED_PORT, LED_BLUE_BIT); + } + } + return 0; } diff --git a/robot/include/main.h b/robot/include/main.h index 92b59e8..97c3bb9 100644 --- a/robot/include/main.h +++ b/robot/include/main.h @@ -3,6 +3,9 @@ #include +uint8_t tx_address[5] = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7}; +uint8_t rx_address[5] = {0xD7, 0xD7, 0xD7, 0xD7, 0xD7}; + void read_temp(void); #endif diff --git a/robot/src/main.c b/robot/src/main.c index 825d74f..1d83295 100644 --- a/robot/src/main.c +++ b/robot/src/main.c @@ -31,21 +31,30 @@ void read_temp(void) int main(void) { init_leds(); - init_servos(); + /* init_servos(); */ init_sonar(); + nrf24_init(); + + nrf24_config(2, 1); // Channel #2, payload: 1 + nrf24_tx_address(tx_address); + nrf24_rx_address(rx_address); // Use green LED as power LED SET(LED_PORT, LED_GREEN_BIT); - run_servos(); + /* run_servos(); */ /* read_temp(); */ + uint8_t data_array[1]; while (1) { uint16_t distance_int_cm = read_sonar(); if (distance_int_cm <= 10 && distance_int_cm != SONAR_ERROR) - SET(LED_PORT, LED_BLUE_BIT); + data_array[0] = 1; else - CLR(LED_PORT, LED_BLUE_BIT); + data_array[0] = 0; + nrf24_send(data_array); + while (nrf24_isSending()); + _delay_ms(SONAR_DELAY); }