]> git.tnoah.ca Git - clock.git/commitdiff
First Working Commit
authorNoah Tomkins <noah@tnoah.ca>
Mon, 6 Jul 2026 21:36:49 +0000 (17:36 -0400)
committerNoah Tomkins <noah@tnoah.ca>
Mon, 6 Jul 2026 21:36:49 +0000 (17:36 -0400)
.gitignore [new file with mode: 0644]
.vscode/c_cpp_properties.json [new file with mode: 0644]
src/clock.cpp
src/clock.h [new file with mode: 0644]
src/display.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..78a1c66
--- /dev/null
@@ -0,0 +1,2 @@
+lib/
+clock
\ No newline at end of file
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644 (file)
index 0000000..07c08df
--- /dev/null
@@ -0,0 +1,16 @@
+{
+    "configurations": [
+        {
+            "name": "Linux",
+            "includePath": [
+                "${workspaceFolder}/**"
+            ],
+            "defines": [],
+            "compilerPath": "/usr/bin/clang",
+            "cStandard": "c17",
+            "cppStandard": "c++17",
+            "intelliSenseMode": "linux-clang-x64"
+        }
+    ],
+    "version": 4
+}
\ No newline at end of file
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8655cf9669f643a302af8a0b7fdeebb8451b8f67 100644 (file)
@@ -0,0 +1,14 @@
+#include "clock.h"
+#include <wiringPi.h>
+#include "display.c"
+
+int main (void) 
+{
+    wiringPiSetupGpio();
+    setupDisplay();
+
+    for (;;)
+    {
+        testDisplay();
+    } 
+}
\ No newline at end of file
diff --git a/src/clock.h b/src/clock.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/display.c b/src/display.c
new file mode 100644 (file)
index 0000000..05ec5b4
--- /dev/null
@@ -0,0 +1,69 @@
+#include <cstdio>
+#include <stdint.h>
+#include <wiringPi.h>
+
+static int digits   [3] = { 17, 27, 22 };
+static int segments [3] = { 23, 24, 25 };
+
+static int binWriteDisplay(uint8_t digit, uint8_t segment) 
+{
+    if (digit > 0b111 || segment > 0b111) 
+    {
+        printf("Digit or Segment must not exceed 0b111 | %d %d \n", digit, segment);
+        return 1;
+    }
+
+    digitalWrite(digits[0], digit % 2);
+    digitalWrite(digits[1], (digit / 2) % 2);
+    digitalWrite(digits[2], (digit / 4) % 2);
+
+    digitalWrite(segments[0], segment % 2);
+    digitalWrite(segments[1], (segment / 2) % 2);
+    digitalWrite(segments[2], (segment / 4) % 2);
+
+    return 0;
+}
+
+static void displayOff (void) 
+{
+    binWriteDisplay(0b111, 0b111);
+}
+
+
+static void printBinary (int num) 
+{
+    for (int i = 3; i >= 0; i--) 
+    {
+        printf("%d", (num >> i) & 1);
+    }
+    printf("\n");
+}
+
+static void testDisplay (void)
+{
+    for (int i = 0; i < 0b111; i++)
+    {
+        for (int j = 0; j < 0b111; j++)
+        {
+            printBinary(i);
+            printBinary(j);
+            printf("\n");
+            binWriteDisplay(i, j);
+            delay(1000);
+        }
+    }
+}
+
+static void setupDisplay (void)
+{
+    for (int i = 0; i < 3; i++)
+    {
+        pinMode(digits[i], OUTPUT);
+        digitalWrite(digits[i], 0);
+
+        pinMode(segments[i], OUTPUT);
+        digitalWrite(segments[i], 0);
+    }
+
+    displayOff();
+}
\ No newline at end of file