Skip to content

Commit

Permalink
update pinreadwrite and do phase 2
Browse files Browse the repository at this point in the history
we discovered a missing but needed function, pinWrite() that was added.
first cut on phase 2 with the tilt switch. using an LED because the
buzzer is pretty anoying. Drives the cats nuts as well.
  • Loading branch information
RichardChambers committed Jan 6, 2018
1 parent 298c06d commit 6f5b2df
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions project11/tiltbuzz_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>

#include "lcd1602.h"
#include "pinreadwrite.h"

int main (int argc, char *argv[])
{
// BUZZPIN is wiringPi Pin #1 or physical pin #12 or GPIO #18
int BUZZPIN = 0;
int SW520DPIN = 2;

if (wiringPiSetup() == -1) {
printf ("Setup wiringPi Failed!\n");
return -1;
}

lcd1602Open (0x27);

pinSetupWrite (BUZZPIN, LOW);
pinSetupRead (SW520DPIN);

lcd1602Write (0, 0, "Welcome to tiltbuzz_1");
delay (2000);

lcd1602Clear ();

int iCount = 20;
for ( ; iCount > 0; iCount--) {
int iDelay = ((iCount % 5) + 1) * 400;
char buffLines[2][24];

// LOW means Vertical, HIGH means tilted.
int iTilt = pinRead (SW520DPIN);

sprintf (buffLines[0], "tiltbuzz_2 %2.2d", iCount);
sprintf (buffLines[1], "SW520D %d", iTilt);
lcd1602Write (0, 0, buffLines[0]);
lcd1602Write (0, 1, buffLines[1]);

// if Vertical then ok, no indicator. if tilt then indicate.
pinWrite (BUZZPIN, ((iTilt) ? 0 : 1));
delay (2000);
}

// clean up the GPIO resources we have been using.
// make sure that things are back to a good state before exit.
pinCleanup (BUZZPIN);
pinCleanup (SW520DPIN);
lcd1602Close();

delay (500);
return 0;
}

0 comments on commit 6f5b2df

Please sign in to comment.