#include <LiquidCrystal.h>
#include <stdio.h>
// shift register pins initialization
int DATA_PIN = 11; // Pin connected to DS of 74HC595(Pin14)
int CLK_PIN = 12; // Pin connected to SH_CP of 74HC595(Pin11)
int LATCH_PIN = 13; // Pin connected to ST_CP of 74HC595(Pin12)
// buttons pin initialization
int button1 = 8;
int button2 = 9;
int button3 = 10;
// car parking sensors
int SENS1 = A0;
int SENS2 = A1;
int SENS3 = A2;
int SENS4 = A3;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLK_PIN, OUTPUT);
pinMode(DATA_PIN, OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
lcd.begin(16, 4); // initialize the lcd
lcd.print(" AVAILABLE");// Print a message to the LCD
lcd.setCursor(3,1);
lcd.print("0");
}
void loop()
{
/*
if (digitalRead(P1) == LOW)
{
toogleP1 =! toogleP1;
if(toogleP1 == true)
{
updateLEDsParking(spaceOne, LED_RED);
counter--;
delay(100);
}
else
{
updateLEDsParking(spaceOne, LED_GREEN);
counter++;
delay(100);
}
lcd.setCursor(3,1);
lcd.print("0");
lcd.print (counter);
lcd.print(" SPACES");
}
if (digitalRead(P2) == LOW)
{
toogleP2 =! toogleP2;
if(toogleP2 == true)
{
updateLEDsParking(spaceTwo, LED_RED);
counter--;
delay(100);
}
else
{
updateLEDsParking(spaceTwo, LED_GREEN);
counter++;
delay(100);
}
lcd.setCursor(3,1);
lcd.print("0");
lcd.print (counter);
lcd.print(" SPACES");
}
if (digitalRead(P3) == LOW)
{
toogleP3 =! toogleP3;
if(toogleP3 == true)
{
updateLEDsParking(spaceThree, LED_RED);
counter--;
delay(100);
}
else
{
updateLEDsParking(spaceThree, LED_GREEN);
counter++;
delay(100);
}
lcd.setCursor(3,1);
lcd.print("0");
lcd.print (counter);
lcd.print(" SPACES");
}
if (digitalRead(P4) == LOW)
{
toogleP4 =! toogleP4;
if(toogleP4 == true)
{
updateLEDsParking(spaceFour, LED_RED);
counter--;
delay(100);
}
else
{
updateLEDsParking(spaceFour, LED_GREEN);
counter++;
delay(100);
}
lcd.setCursor(3,1);
lcd.print("0");
lcd.print (counter);
lcd.print(" SPACES");
}
/*
if (digitalRead(P2) == LOW)
{
counter++;
lcd.setCursor(1,0);
lcd.print("Counter: ");
lcd.setCursor(10,0);
lcd.print (counter);
delay(500);
}
*/
}
/*************************************************************/
/*************************************************************/ /*
void updateShiftRegister()
{
digitalWrite(latchPin, LOW); // Output low level to latchPin
shiftOut(dataPin, clockPin, LSBFIRST, LEDs); // Send serial data to 74HC595
digitalWrite(latchPin, HIGH); // Output high level to latchPin, and 74HC595 will update the data to the parallel output port.
}
/*************************************************************/
/*
void updateLEDsParking(int parkingSpace, int status)
{
if (parkingSpace == spaceOne)
{
if(status) LEDs = ((LEDs&0b10111111)| 0b10000000);
else LEDs = ((LEDs&0b01111111)|0b01000000);
}
if (parkingSpace == spaceTwo)
{
if(status) LEDs = ((LEDs&0b11101111)| 0b00100000);
else LEDs = ((LEDs&0b11011111)|0b00010000);
}
if (parkingSpace == spaceThree)
{
if(status) LEDs = ((LEDs&0b11111011)| 0b00001000);
else LEDs = ((LEDs&0b11110111)|0b00000100);
}
if (parkingSpace == spaceFour)
{
if(status) LEDs = ((LEDs&0b11111110)| 0b00000010);
else LEDs = ((LEDs&0b11111101)|0b00000001);
}
updateShiftRegister();
delay(200);
}
*/