Added base files

This commit is contained in:
Austen Adler 2017-01-03 16:17:10 +00:00
parent 738f930526
commit a3a20c98cd
9 changed files with 225 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
flush
new
prompt
sr

4
a Executable file
View File

@ -0,0 +1,4 @@
run() {
echo "building..."
gcc -Wall -o "$1"{,.c} -lwiringPi -g -std=c11 && (echo "running...";./$*)
}

64
ardshift.c Normal file
View File

@ -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);
}

18
blink.c Normal file
View File

@ -0,0 +1,18 @@
#include <wiringPi.h>
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 ;
}

18
blink.py Executable file
View File

@ -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()

17
flush.c Normal file
View File

@ -0,0 +1,17 @@
#include <wiringPi.h>
#include <stdlib.h>
#include <stdio.h>
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;
}

47
new.c Normal file
View File

@ -0,0 +1,47 @@
#include <wiringPi.h>
#include <stdio.h>
#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 ;
}

22
prompt.c Normal file
View File

@ -0,0 +1,22 @@
#include <wiringPi.h>
#include <stdio.h>
#include <stdbool.h>
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;
}

31
sr.c Normal file
View File

@ -0,0 +1,31 @@
/*
* sr.c:
* Shift register test program
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <sr595.h>
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;
}