Created
June 11, 2016 20:21
-
-
Save insom/d90d0b80a9f210e3c736e0bba7a81d04 to your computer and use it in GitHub Desktop.
Make pretty lights using a Raspberry Pi and a 74374N octal flip-flop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _BSD_SOURCE | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#define INPUT 17 | |
#define OE 18 | |
#define CLK 27 | |
void setup_pin(int pin) { | |
FILE *f; | |
char buf[512] = {0}; | |
f = fopen("/sys/class/gpio/export", "w"); | |
fprintf(f, "%d\n", pin); | |
fclose(f); | |
sprintf(buf, "/sys/class/gpio/gpio%d/direction", pin); | |
f = fopen(buf, "w"); | |
fprintf(f, "out\n"); | |
fclose(f); | |
} | |
void set_pin(int pin, int value) { | |
FILE *f; | |
char buf[512] = {0}; | |
sprintf(buf, "/sys/class/gpio/gpio%d/value", pin); | |
f = fopen(buf, "w"); | |
fprintf(f, "%d\n", value); | |
fclose(f); | |
} | |
int main(void) { | |
setup_pin(CLK); | |
setup_pin(OE); | |
setup_pin(INPUT); | |
set_pin(OE, 0); | |
while(1) { | |
for(int i = 0; i < 8; i++) { | |
set_pin(CLK, 0); | |
set_pin(INPUT, random() & 1); | |
set_pin(CLK, 1); | |
} | |
sleep(1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment