Last active
March 16, 2019 16:32
-
-
Save connected/9efc6580223e6d2c200730f0b55da61b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <RF22ReliableDatagram.h> | |
#include <Adafruit_GFX.h> | |
#include "Adafruit_ILI9340.h" // Hardware-specific library | |
#include <RF22.h> | |
#include <SPI.h> | |
#define CLIENT_ADDRESS 1 | |
#define SERVER_ADDRESS 2 | |
RF22ReliableDatagram rf22(SERVER_ADDRESS); | |
#if defined(__SAM3X8E__) | |
#undef __FlashStringHelper::F(string_literal) | |
#define F(string_literal) string_literal | |
#endif | |
#define TFT_RST 7 | |
#define TFT_DC 8 | |
#define TFT_CS 9 | |
Adafruit_ILI9340 tft = Adafruit_ILI9340(TFT_CS, TFT_DC, TFT_RST); | |
uint8_t row = 0; | |
void setup() { | |
Serial.begin(9600); | |
tft.begin(); | |
tft.fillScreen(ILI9340_BLACK); | |
if (!rf22.init()) { | |
Serial.println("RF22 init failed"); | |
} | |
} | |
// uint8_t data[] = "And hello back to you"; | |
uint8_t buf[RF22_MAX_MESSAGE_LEN]; | |
void loop() { | |
uint8_t r, g, b; | |
uint8_t len = sizeof(buf); | |
uint8_t from; | |
if (rf22.recvfromAck(buf, &len, &from)) { | |
digitalWrite(10, LOW); | |
Serial.print("got request from : 0x"); | |
// Serial.print(from, HEX); | |
// Serial.print(": "); | |
// Serial.println((char*)buf); | |
// len == 48? | |
for (int jj = 0; jj < len; jj=jj+3) { | |
Serial.println(jj); | |
Serial.println("COL"); | |
r = buf[jj]; | |
g = buf[jj + 1]; | |
b = buf[jj + 2]; | |
Serial.print("R "); | |
Serial.print(r); | |
Serial.print(" G "); | |
Serial.print(g); | |
Serial.print(" B "); | |
Serial.println(b); | |
tft.drawPixel(jj / 3, row, tft.Color565(r, g, b)); | |
} | |
row++; | |
// if (!rf22.sendtoWait(data, sizeof(data), from)) { | |
// Serial.println("sendtoWait failed"); | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment