#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Keypad.h>
#include <WiFi.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define BUTTON 4
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
//TwoWire wire = TwoWire(0);
//Adafruit_SSD1306 display;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t rowPins[ROWS] = { 38, 37, 36, 35 }; // Pins connected to C1, C2, C3, C4
uint8_t colPins[COLS] = { 1, 2, 48, 47 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char ssid[] = "Wokwi-GUEST";
char password[] = "";
const String NwsUrl = "https://api.weather.gov/points/";
const String geocodeUrl = "https://geocode.xyz/";
char zipcode[5];
int zipIndex = 0;
void inputMessage();
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//Wire.begin();
if (!Wire.begin()) {
Serial.println("failed to start wire");
for (;;);
}
//display = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//button setup
pinMode(BUTTON, INPUT_PULLUP);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
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();
Serial.println("Ready for Action");
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
Serial.print("CONNECTED to SSID: ");
Serial.println(ssid);
display.print("Connection Successful!");
display.display();
delay(5000);
inputMessage();
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
}
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
display.print(key);
display.display();
zipcode[zipIndex] = key;
zipIndex += 1;
}
int buttonVal = digitalRead(BUTTON);
if ( buttonVal == LOW) {
display.clearDisplay();
display.setCursor(0, 0);
char msg[] = "Getting Forecast Data for Zipcode ";
for (int i = 0; i < 35; i++) {
display.print(msg[i]);
display.display();
delay(1);
}
for (int i = 0; i < 5; i++) {
display.print(zipcode[i]);
display.display();
delay(1);
}
delay(5000);
inputMessage();
for (int i = 0; i < 5; i++) {
Serial.print(zipcode[i]);
}
for (int i = 0; i < 5; i++) {
zipcode[i] = 0;
}
}
display.display();
}
void inputMessage() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Enter Zip Code: ");
display.display();
}