Hey I'm quite new at coding.
I'm currently doing a course in embedded systems. The first assignment is creating a lcd clock. unfortunately due to lockdown i dont have access to the board and lcd screen that the code template was created for.
The teacher decided that he is happy with me using the arduino nano and wavgat oled 128x64 1306 screen on hand. unfortunately im having issue compiling saying "Error compiling for board Arduino Nano". i would appreciate any assistance in getting this to work.
[code]
/**
Project: AVR X-mini clock
File: tod_clock_outline_arduino.INO
The LCD module and push-buttons must be wired according to the library requirements.
(Refer to AVR board code library documentation.)
Operating instructions:
To set the time, hold down button 'A' and press 'B' to set hours, 'C' to set minutes.
To switch between 24-hour and 12-hour (am/pm) display mode, press button 'D'.
Author: <Cameron Vonarx> 2020-08-16
*/
// Function prototype declarations...
// `````````````````````````````````````
#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 64 // OLED display height, in pixels
byte ButtonA = 5;
byte ButtonB = 4;
byte ButtonC = 3;
byte ButtonD = 2;
// 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 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void DisplayTimeOfDay();
void SettingTimeOfDay();
// ------------ Global variables --------------------------------------
char rtcHour, rtcMinutes, rtcSeconds; // time-of-day clock "registers" (24-hour mode)
unsigned long LEDturnOffTime; // Time to turn LED off (ms since Reset)
boolean is12hourMode; // Flag: True if 12-hour display mode selected
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(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
// put your setup code here, to run once:
// Invert and restore display, pausing in-between
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
byte toggle = 0;
rtcHour = 11; // Initialise time-of-day "registers"
rtcMinutes = 50;
rtcSeconds = 0;
// Configure I/O pins (data directions) for push-buttons and LED(s)
bitSet(LED_BUILTIN, 1);
display.setCursor(0, 0);
display.println("AVR X'mini clock"); // string to go on top line
pinMode(ButtonA, INPUT);
pinMode(ButtonB, INPUT);
pinMode(ButtonC, INPUT);
pinMode(ButtonD, INPUT);
}
void loop() { // put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
unsigned long previousMillis;
unsigned long previousMillis2;
unsigned long previousMillis3;
if (currentMillis - previousMillis > 500) // True every 0.5 second
{
previousMillis = currentMillis;
if (currentMillis - previousMillis3 > 1000) // <---- this happens every 1 second (500ms x 2)
{
rtcSeconds++;
bitSet(LED_BUILTIN, 1); // Turn heartbeat LED ON
LEDturnOffTime = millis() + 100;
if (rtcSeconds >= 60) // 60 seconds up; "roll-over" minute
{
rtcSeconds = 0;
rtcMinutes++;
}
if (rtcMinutes >= 60) // 60 minutes up; "roll-over" Hour
{
rtcMinutes = 0;
rtcHour++;
}
if (rtcHour >= 24) // 24 hours up; "roll-over" day
{
rtcHour = 0;
}
}
}
if (currentMillis - previousMillis2 > 50)
{
previousMillis2 = currentMillis;
digitalRead(ButtonD); // ButtonScan is called every 50ms
}
// Check if the LED on-time (duty) has reached 100ms...
if (millis() >= LEDturnOffTime) bitClear(LED_BUILTIN, 0); // Turn LED off
// test for button A held down --> setting mode
if (ButtonA = HIGH)
{
SettingTimeOfDay();
}
}
void DisplayTimeOfDay() {
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
byte hours_12 = 0;
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
for (int16_t i = 0; i < 256; i++) {
if (i == '\n') display.write(' ');
else display.write(i);
}
if (ButtonD = HIGH)
{
display.setCursor(1, 2);
// Determine value of hours_12 based on value of rtcHour
if (hours_12 >= 12) // 12 hours up; "roll-over" day
{
hours_12 = 0;
}
// 12-hour mode only
if ((hours_12 / 10) == 0) display.write(' ');
else display.write((hours_12 / 10) + '0');
display.write((hours_12 % 10) + '0');
}
// what if 24-hour mode selected ?
if (ButtonD = HIGH)// 24 hours up; "roll-over" day
{
display.setCursor(1, 2);
if (hours_12 >= 24)
{
hours_12 = 0;
}
if ((hours_12 / 10) == 0) display.write(' ');
else display.write((hours_12 / 10) + '0');
display.write((hours_12 % 10) + '0');
}
display.print(":");
display.write((rtcMinutes / 10) + '0' );
display.write((rtcMinutes % 10) + '0' );
display.print(":");
display.write((rtcSeconds / 10) + '0' );
display.write((rtcSeconds % 10) + '0' );
display.write(' ');
// 12-hour mode only
if (rtcHour < 12) display.print("am");
else display.print("pm");
}
//void testdrawchar(void) {
//display.clearDisplay();
//display.setTextSize(1); // Normal 1:1 pixel scale
//display.setTextColor(SSD1306_WHITE); // Draw white text
//display.setCursor(0, 0); // Start at top-left corner
//display.cp437(true); // Use full 256 char 'Code Page 437' font
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
//for(int16_t i=0; i<256; i++) {
//if(i == '\n') display.write(' ');
//else display.write(i);
//}
// display.display();
// delay(2000);
// }
/*
To do: Describe workings of this function. (What does it do and how?)
Add C code to implement the comments!
`````````````````````````````````````
*/
void SettingTimeOfDay() // if button B is hit, adjust hours setting, setHours
{
if (ButtonB = HIGH)
{
rtcHour ++;
rtcSeconds = 0;
}
// if button C is hit, adjust minutes setting, setMins
if (ButtonC = HIGH)
{
rtcMinutes ++;
rtcSeconds = 0;
}
}
// real-time seconds = 0
// end of file
[/code]