1
0

Added basic Button and Display IO

This commit is contained in:
Lukas Bachschwell 2015-09-18 19:32:11 +02:00
parent dbf9fc1d4f
commit 835c455762
2 changed files with 52 additions and 8 deletions

View File

@ -1,6 +1,4 @@
#include <Arduino.h>
//#include <SPI.h>
//#include <SD.h>
#ifndef BEERBOX_IS_INCLUDED
#define BEERBOX_IS_INCLUDED

View File

@ -1,12 +1,16 @@
#include <SPI.h>
#include <Wire.h>
#include <SD.h>
#include <LiquidCrystal_I2C.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "beerbox.h"
#include <Adafruit_Fingerprint.h>
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);
LiquidCrystal_I2C lcd(0x38, 8, 2); // 0x38 for PCF***A on address 000
//######### RFID CONSTANTS ##########
@ -27,12 +31,19 @@ const int chipSelect = 53;
char leckmich[255];
Beerbox *box;
int drinksMax = 1;
int lastButtonState = 1;
int currentDrink = 0;
void setup() {
//generall debugging
Serial.begin(115200);
//LCD init
lcd.init();
pinMode(2,INPUT_PULLUP);
//Fingerprint init
finger.begin(57600);
if (finger.verifyPassword()) {
@ -64,6 +75,9 @@ void setup() {
box = new Beerbox;
box = read_beerbox(box);
lcd.print("BOXready");
lcd.setCursor(0, 1);
}
@ -72,16 +86,44 @@ void loop() {
checkFinger();
checkRFID();
checkButton();
//Person myPerson = read_person(box, "p001");
//read_person(box, "p002");
//while (1);
}//end loop
void checkButton() {
//one change per click to make seleting drinks easier for the drunken
//if (digitalRead(2) != lastButtonState) {
//delayMicroseconds(50); //debounce delay
if (digitalRead(2) != lastButtonState) {
//ok we have a change!
if (digitalRead(2) == LOW) {
//pushed
if(currentDrink == drinksMax-1) currentDrink = -1;
currentDrink++;
Serial.println(box->drinks[currentDrink].name);
lcd.clear();
lcd.print("Drink:");
lcd.setCursor(0, 1);
lcd.print(box->drinks[currentDrink].name);
}
else {
//released
}
lastButtonState = digitalRead(2);
}
//}
}
bool checkFinger() {
uint8_t p = finger.getImage();
@ -94,12 +136,15 @@ bool checkFinger() {
if (p != FINGERPRINT_OK) return -1;
// found a match!
//Serial.print("Found ID #"); Serial.print(finger.fingerID);
//Serial.print(" with confidence of "); Serial.println(finger.confidence);
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
//TODO @ALEX Do something with finger ID
// finger.fingerID
int getFingerIndex(Person* persons, finger.fingerID)
}
void checkRFID() {
@ -208,12 +253,13 @@ Beerbox* read_beerbox(Beerbox *box) {
for (i = 0; (i < NUM_OF_DRINKS) && (box->drinks[i].price != -1); i++) {
sprintf(leckmich, "drink number : %s\nprice: %d\nquantity: %d\n\n", box->drinks[i].name, box->drinks[i].price, box->drinks[i].quantity);
sprintf(leckmich, "drink number %i: %s\nprice: %d\nquantity: %d\n\n", i ,box->drinks[i].name, box->drinks[i].price, box->drinks[i].quantity);
Serial.print(leckmich);
}
if (i < NUM_OF_DRINKS) {
sprintf(leckmich, "Slots %d - %d are not in use!\n", i + 1, NUM_OF_DRINKS);
drinksMax = i;
Serial.print(leckmich);
}