/*
14CORE Test Code for: Light Blocking Switch on C Code
.:+osysso++:`
`+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////-
`odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////`
-hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------`
`hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++
+dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ````````````
ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+
odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` `
-dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y.
/dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+.
-yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` `
:ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/
.:oyhhhhhhhso:` `.
```
*/
#include <wiringPi.h>
#include <stdio.h>
#define SensorPin 0
#define LedOutput 1
void INOUT(char* ledstate)
{
pinMode(Rpin, OUTPUT);
if (ledstate == "OUTPUT")
{
digitalWrite(LedOutput, HIGH);
}
else if (ledstate == "INPUT")
{
digitalWrite(LedOutput, LOW);
}
else
printf("Error Led Output");
}
int main(void)
{
if(wiringPiSetup() == -1) //If no response from wiringpi.h print
{
printf("Wiring Pi Initialization Faild");
return 1;
}
pinMode(SensorPin, INPUT);
INOUT("INPUT");
while(1){
if(0 == digitalRead(SensorPin)){
delay(10);
if(0 == digitalRead(SensorPin)){
INOUT("OUTPUT");
printf("Detected!\n");
}
}
else if(1 == digitalRead(SensorPin)){
delay(10);
if(1 == digitalRead(SensorPin)){
while(!digitalRead(SensorPin));
INOUT("INPUT");
}
}
}
return 0;
}