/* LCD specifications: lcd has pcd8544 SPI driver IC lcd is 84x48 monochrome pixels lcd is not compatible with nrf24L01+ while using hardware SPI lcd is separated to 6 rows of 8x84 pixels lcd library can display monochrome bitmaps as "static const byte "array_name"[]" lcd library can only print characters inside rows, but not in between them lcd is addressed like this: Y: X:0 1 2 3 4 5 6 7 ... 83 (because pixels counted from 0) 1 2 3 4 5 (because rows are counted from 0) to print charracter in bottom right corner: lcd.setCursor(77,5); (83(lcd width in pixels)-6(character width)=77,5 - because we are printing in 6th row) Input specifications: analog sticks are read by ADCs (analog to digital converters) and return 4 byte integer value (0 - 1023) buttons are read by pulled-up digital pins and return boolean value of 0 or 1 Radio specifications: radio has nrf24L01+ chip with additional aplifier IC radio can work as receiver and transmitter radio can receive ACK packets after a transmission */ #include #include "nRF24L01.h" #include "RF24.h" #include RF24 radio(9,10); static PCD8544 lcd; static const byte radar[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x08, 0x08, 0x08, 0x04, 0x04, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x0C, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x40, 0x40, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x40, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x70, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x10, 0x08, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x04, 0x08, 0x10, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0E, 0x70, 0x80, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x3C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x04, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x0C, 0x10, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, }; const uint64_t pipe = 0xE8E8F0F0E1LL; float X; float Y; int TXDATA[5]; int RXDATA[2]; int menu; int distance; int tab; int wehicleType = 1; int channel; int analog1State; int analog2State; int lastAnalog1State; int lastAnalog2State; int selected1; int selected2; int pointer1 = 1; int pointer2; int lastPointer1; int lastPointer2; bool detected[14][6]; bool done; bool autoACK; bool state=1; //0 = controll 1 = menu bool button1State; bool button2State; bool lastButton1State; bool lastButton2State; void setup(void){ pinMode(17,OUTPUT); digitalWrite(17,LOW); pinMode(A0,INPUT); pinMode(A1,INPUT); pinMode(A2,INPUT); pinMode(A3,INPUT); pinMode(1,INPUT_PULLUP); pinMode(0,INPUT_PULLUP); lcd.begin(84,48); lcd.setContrast(59); // lcd.createChar(0, glyph); radio.begin(); radio.openWritingPipe(pipe); //radio.setPayloadSize(2); //radio.setRetries(15,15); // radio.setAutoAck(1); // autoACK = 1; // radio.enableAckPayload(); radio.setPALevel(RF24_PA_MAX); radio.setDataRate(RF24_250KBPS); radio.setChannel(125); channel = 125; } void loop(void){ //read all input from buttons and analog sticks TXDATA[0]=analogRead(A2); TXDATA[1]=analogRead(A3); TXDATA[2]=analogRead(A0); TXDATA[3]=analogRead(A1); button1State = !digitalRead(1); button2State = !digitalRead(0); bitWrite(TXDATA[4],0,button1State); bitWrite(TXDATA[4],1,button2State); //check for a state button press if (button1State != lastButton1State){ if (button1State == HIGH) { state = !state; //change state pointer1 = 1; //reset values tab = 0; lcd.clear(); //clear lcd } delay(50); //allow some time for debounce } lastButton1State = button1State; //lock in button state if (state == 0){ printControll(); //print action menu or radar scope } if (state == 1){ printSettings(); //print settings menu } } void printControll(){ if (button2State != lastButton2State) { if (button2State == HIGH) { lcd.setCursor(0,0); lcd.drawBitmap(radar,84,48); } delay(50); } lastButton2State = button2State; radio.write(&TXDATA,sizeof(TXDATA)); //send some data if (radio.isAckPayloadAvailable()){ //check if some data is returned after sending radio.read(&RXDATA,sizeof(RXDATA)); //if data is returned - read it } distance=map(constrain(RXDATA[1],0,200),0,200,0,41); //constrain and map returned distance to LCD X = RXDATA[1] * cos((PI / 180 * RXDATA[0]))+41; //calculate X coordinate Y = -RXDATA[1] * sin((PI / 180 * RXDATA[0]))+41; //calculate Y coordinate //check X and Y coordinates for a match on a 13x6 grid for (int x = 0; x <= 13; x++){ for (int y = 0; y <= 5; y++){ if ((X>=x*6)&&(X=y*8)&&(YEND){ pointer1 = START; } } if (analog1State == 2){ lastPointer1=pointer1; pointer1--; if (pointer1