/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x32 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
0b00000001, 0b11000000,
0b00000001, 0b11000000,
0b00000011, 0b11100000,
0b11110011, 0b11100000,
0b11111110, 0b11111000,
0b01111110, 0b11111111,
0b00110011, 0b10011111,
0b00011111, 0b11111100,
0b00001101, 0b01110000,
0b00011011, 0b10100000,
0b00111111, 0b11100000,
0b00111111, 0b11110000,
0b01111100, 0b11110000,
0b01110000, 0b01110000,
0b00000000, 0b00110000 };
// 'wifi_ap', 128x32px
const unsigned char Twifi_ap [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xc0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0xff, 0xff,
0xff, 0xfc, 0x00, 0x0f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xff,
0xff, 0xe0, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x07, 0xff,
0xff, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x07, 0xff, 0xf0, 0x00, 0xff,
0xfc, 0x00, 0x7f, 0xff, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x7f, 0xfe, 0x00, 0x3f,
0xf0, 0x01, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f, 0xff, 0x80, 0x0f,
0xe0, 0x07, 0xff, 0xe0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xe0, 0x07,
0x80, 0x0f, 0xff, 0x80, 0x0f, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x01, 0xff, 0xf0, 0x01,
0x80, 0x1f, 0xff, 0x00, 0x1f, 0xff, 0xf0, 0x00, 0x00, 0x07, 0xff, 0xfc, 0x00, 0xff, 0xf8, 0x01,
0x00, 0x3f, 0xff, 0x00, 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xfc, 0x00, 0xff, 0xfc, 0x00,
0x00, 0x3f, 0xff, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xfc, 0x00, 0xff, 0xfc, 0x00,
0x00, 0x3f, 0xff, 0x80, 0x1f, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0xff, 0xfc, 0x00,
0x80, 0x1f, 0xff, 0xc0, 0x0f, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x01, 0xff, 0xf8, 0x01,
0x80, 0x0f, 0xff, 0xe0, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xc0, 0x07, 0xff, 0xf0, 0x01,
0xe0, 0x07, 0xff, 0xf8, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x1f, 0xff, 0xe0, 0x07,
0xf0, 0x01, 0xff, 0xff, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0xff, 0xff, 0x80, 0x0f,
0xfc, 0x00, 0x7f, 0xff, 0xf0, 0x01, 0xfe, 0x00, 0x00, 0x3f, 0xc0, 0x0f, 0xff, 0xfe, 0x00, 0x3f,
0xff, 0x00, 0x0f, 0xff, 0xff, 0xc1, 0xfe, 0x00, 0x00, 0x3f, 0xc1, 0xff, 0xff, 0xf0, 0x00, 0xff,
0xff, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x07, 0xff,
0xff, 0xfc, 0x00, 0x0f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xff,
0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff,
0xff, 0xff, 0xfc, 0x01, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
const unsigned char Tscubic_logo[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00,
0x00, 0x7f, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0x07, 0xff, 0xff, 0xc0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x03, 0xff, 0xff, 0xf0, 0x00, 0x7f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xe0,
0x00, 0x3f, 0xff, 0xfe, 0x03, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00,
0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xf0, 0x00,
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0x80, 0x00,
0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x01, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 528)
const char* ssid_sta="Iphone";
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(20); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.drawBitmap(0, 0, Tscubic_logo, 128, 20, 1);
display.display();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 22); // Start at top-left corner
String wifi_str = "Connecting " + String(ssid_sta) + "...";
display.print(wifi_str);
display.display();
display.clearDisplay();
pinMode(18, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
Serial.println(digitalRead(4));Serial.println(digitalRead(18));
}
void draw_text(int x, int y, String str) {
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(x, y); // Start at top-left corner
display.print(str);
}
String slave_on;
bool get_but1=0;
bool get_but2=0;
bool rec_data() {
static int count_slave_1 = 0;
static int count_slave_2 = 0;
static uint8_t data_rec_count = 0;
if (data_rec_count >= 5) data_rec_count = 0;
bool but1=digitalRead(18);
bool but2=digitalRead(4);
if(but1==0) {
get_but1=1;
}
else{
get_but1=0;
}
if(but2==0){
get_but2=1;
}
else{
get_but2=0;
}
return 1;
}
void loop() {
rec_data();
static unsigned long time_ = millis();
if(millis() - time_ > 1000)
{
String str_ = "NRF:";
slave_on="--";
if(get_but1==1){
if(get_but2==1)
{
slave_on="01-02";
}
else{
slave_on="01";
}
}
else{
if(get_but2==1)slave_on="02";
}
display.clearDisplay();
draw_text(0,0,str_+slave_on);
draw_text(0,15,"GPS:Not Found");
draw_text(0,25,"HTTP:201");
display.display();
time_ = millis();
}
}