diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ac559f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +flush +new +prompt +sr diff --git a/a b/a new file mode 100755 index 0000000..4fdce38 --- /dev/null +++ b/a @@ -0,0 +1,4 @@ +run() { + echo "building..." + gcc -Wall -o "$1"{,.c} -lwiringPi -g -std=c11 && (echo "running...";./$*) +} diff --git a/ardshift.c b/ardshift.c new file mode 100644 index 0000000..b5c6264 --- /dev/null +++ b/ardshift.c @@ -0,0 +1,64 @@ +int latch = 8; +int clock = 12; +int data = 11; + +void setup() { + pinMode(latch, OUTPUT); + pinMode(clock, OUTPUT); + pinMode(data, OUTPUT); + cclear(); //Clear to make sure everythings tight +} + +void loop() { + one(); + one(); + one(); + one(); + one(); + one(); + one(); + one(); + ssend(); +} + +void cclear() { + //set all to zero + zer(); + zer(); + zer(); + zer(); + zer(); + zer(); + zer(); + zer(); +} + +void one() { + //just an abbreviation of dchigh + dchigh(); +} + +void zer() { + //another abbreviation for chigh + chigh(); +} + +void dchigh() { + //start clock, input a one, close clock. (make the bit a 1) + digitalWrite(data, HIGH); + digitalWrite(clock, HIGH); + digitalWrite(clock, LOW); + digitalWrite(data, LOW); +} + +void chigh() { + //start and stop clock. (make the bit a 0) + digitalWrite(clock, HIGH); + digitalWrite(clock, LOW); +} + +void ssend() { + //start latch, then stop. (send the bits) + digitalWrite(latch, HIGH); + digitalWrite(latch, LOW); +} diff --git a/blink.c b/blink.c new file mode 100644 index 0000000..5a2e366 --- /dev/null +++ b/blink.c @@ -0,0 +1,18 @@ +#include +int pin = 3; +void blink() { + digitalWrite (pin, HIGH); + delay (500); + digitalWrite (pin, LOW); + delay (500); +} + +int main (void) +{ + wiringPiSetup (); + pinMode (pin, OUTPUT); + for (;;) { + blink(); + } + return 0 ; +} diff --git a/blink.py b/blink.py new file mode 100755 index 0000000..d59dcc2 --- /dev/null +++ b/blink.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +import RPi.GPIO as GPIO +import time +# blinking function +def blink(pin): + GPIO.output(pin,GPIO.HIGH) + time.sleep(1) + GPIO.output(pin,GPIO.LOW) + time.sleep(1) + return +# to use Raspberry Pi board pin numbers +GPIO.setmode(GPIO.BOARD) +# set up GPIO output channel +GPIO.setup(7, GPIO.OUT) +# blink GPIO17 50 times +for i in range(0,500): + blink(7) +GPIO.cleanup() diff --git a/flush.c b/flush.c new file mode 100644 index 0000000..57fe4a7 --- /dev/null +++ b/flush.c @@ -0,0 +1,17 @@ +#include +#include +#include +int main(int argc, char **argv){ + wiringPiSetup(); + if(argc <= 1){ + printf("No arguments\n"); + return 1; + } + for(int i=1; i < argc; i++){ + const int cur = atoi(argv[i]); + printf("Shutting off pin %d\n", cur); + pinMode(cur, OUTPUT); + digitalWrite(cur, LOW); + } + return 0; +} diff --git a/new.c b/new.c new file mode 100644 index 0000000..1b86062 --- /dev/null +++ b/new.c @@ -0,0 +1,47 @@ +#include +#include +#define LATCH_PIN 2 +#define CLOCK_PIN 0 +#define DATA_PIN 3 +const int zeroes[] = {0, 0, 0, 0, 0, 0, 0, 0}; +const int ones[] = {1, 1, 1, 1, 1, 1, 1, 1}; +const int checker1[] = {0, 1, 0, 1, 0, 1, 0, 1}; +const int checker2[] = {1, 0, 1, 0, 1, 0, 1, 0}; +void dWrite(int i, int j){ + delay(10); + digitalWrite(i, j); +} +void ssend() { + dWrite (LATCH_PIN, HIGH); + dWrite (LATCH_PIN, LOW); +} +void write(int mode){ + printf("Writing: (%d)\n", mode); + dWrite(DATA_PIN, mode); + dWrite(CLOCK_PIN, HIGH); + dWrite(CLOCK_PIN, LOW); + dWrite(DATA_PIN, LOW); +} +void writeLine(const int modes[8]) { + for(int i = 0; i < 8; i++) { + write(modes[i]); + //write(1); + } +} +void cclear() { + writeLine(zeroes); + ssend(); +} +int main (void) { + wiringPiSetup (); + pinMode (DATA_PIN, OUTPUT); + pinMode (CLOCK_PIN, OUTPUT); + pinMode (LATCH_PIN, OUTPUT); + for (;;) { + writeLine(checker1); + ssend(); + writeLine(checker2); + ssend(); + } + return 0 ; +} diff --git a/prompt.c b/prompt.c new file mode 100644 index 0000000..98c4347 --- /dev/null +++ b/prompt.c @@ -0,0 +1,22 @@ +#include +#include +#include +void blink(int pin) { + digitalWrite (pin, HIGH); + delay (500); + digitalWrite (pin, LOW); + delay (500); +} +int main(){ + wiringPiSetup(); + int i; + while(true){ + printf("Write pin: "); + scanf("%d", &i); + pinMode (i, OUTPUT); + printf("Blinking: (%d)\n", i); + blink(i); + blink(i); + } + return 0; +} diff --git a/sr.c b/sr.c new file mode 100644 index 0000000..fa0a9ba --- /dev/null +++ b/sr.c @@ -0,0 +1,31 @@ +/* + * sr.c: + * Shift register test program + * + * Copyright (c) 2012-2013 Gordon Henderson. + *********************************************************************** + */ + +#include +#include +#include + +int main (void) +{ +// int i, bit; + + wiringPiSetup (); + + // Pin base 100 for 10 pins. + // Use wiringPi pins 0, 1 & 2 for data, clock and latch + sr595Setup (100, 8, 2, 3, 0); + + printf ("Raspberry Pi - Shift Register Test\n"); + + for (;;) { + digitalWrite (106, 1); + digitalWrite(104, 1); + } + return 0; + +}