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.
This commit is contained in:
parent
92c3842ca9
commit
4ea41527f1
@ -3,4 +3,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t tx_address[5] = {0xD7, 0xD7, 0xD7, 0xD7, 0xD7};
|
||||
uint8_t rx_address[5] = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7};
|
||||
|
||||
#endif
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user