From: Noah Tomkins Date: Mon, 6 Jul 2026 21:36:49 +0000 (-0400) Subject: First Working Commit X-Git-Url: https://git.tnoah.ca/?a=commitdiff_plain;h=063f86aa6c45b6626c238ff97d9f2ba6f9b9c711;p=clock.git First Working Commit --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78a1c66 --- /dev/null +++ b/.gitignore @@ -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 index 0000000..07c08df --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -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 diff --git a/src/clock.cpp b/src/clock.cpp index e69de29..8655cf9 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -0,0 +1,14 @@ +#include "clock.h" +#include +#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 index 0000000..e69de29 diff --git a/src/display.c b/src/display.c new file mode 100644 index 0000000..05ec5b4 --- /dev/null +++ b/src/display.c @@ -0,0 +1,69 @@ +#include +#include +#include + +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