Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ThiBarduino
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnSELECT 4
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in < 790) return btnSELECT;
}
void setup()
{
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(0, OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A2,OUTPUT);
digitalWrite(2,HIGH);//2 OFF
digitalWrite(0,HIGH);//4 OFF
analogWrite(A4,255);//6 OFF
analogWrite(A2,255);//8 OFF
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0); // first lcd line
lcd.print("Thi'Barduino"); // print a simple message
lcd.setCursor(0,1); // second lcd line
lcd.print("vers 1.5-demo");
delay(3000); // wait 3s
lcd.clear(); // clear screen
}
void loop()
{
// put your main code here, to run repeatedly:
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons(); // read the buttons
lcd.print(lcd_key);
lcd.setCursor(15,0);
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnSELECT:
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("S");
// debut distribution
// fin distribution
delay(500);
lcd.clear();
break;
}
}
}
const String boissons[] = {"rien ","thidrink","labdrink","mix C","mix D","mix E","mix F","mix G","mix H","mix I","ntrs "};
const String recettes[] = {"00000000","01000000","02000000","03000000","04000000","05000000","06000000","07000000","08000000","09000000","22222222"};
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int boisson = 0;
int boisson_count = sizeof(boissons)/ sizeof(boissons[0]);
const String hexa = "0123456789abcdef";
void distributeur(String seed)
{
lcd.setCursor(8,0);
lcd.print(seed);
for (int vanne = 1; vanne <= 8; vanne++)
{
digitalWrite(3,HIGH);//1 OFF
digitalWrite(2,HIGH);//2 OFF
digitalWrite(1,HIGH);//3 OFF
digitalWrite(0,HIGH);//4 OFF
analogWrite(A5,255);//5 OFF
analogWrite(A4,255);//6 OFF
analogWrite(A3,255);//7 OFF
analogWrite(A2,255);//8 OFF
lcd.setCursor(0,1);
lcd.print(seed[vanne-1]);
for(int i=0; i<=15;i++)
{
lcd.setCursor(7+vanne,1);
lcd.print(String(i,HEX));
lcd.setCursor(0,1);
if(seed[vanne-1]==hexa[i]){
digitalWrite(3,HIGH);//1 OFF
digitalWrite(2,HIGH);//2 OFF
digitalWrite(1,HIGH);//3 OFF
digitalWrite(0,HIGH);//4 OFF
analogWrite(A5,255);//5 OFF
analogWrite(A4,255);//6 OFF
analogWrite(A3,255);//7 OFF
analogWrite(A2,255);//8 OFF
break;
}
if(vanne==1)
{
digitalWrite(3,LOW);//1 ON
}
if(vanne==2)
{
digitalWrite(2,LOW);//2 ON
}
if(vanne==3)
{
digitalWrite(1,LOW);//3 ON
}
if(vanne==4)
{
digitalWrite(0,LOW);//4 ON
}
if(vanne==5)
{
analogWrite(A5,0);//5 ON
}
if(vanne==6)
{
analogWrite(A4,0);//6 ON
}
if(vanne==7)
{
analogWrite(A3,0);//7 ON
}
if(vanne==8)
{
analogWrite(A2,0);//8 ON
}
delay(1000);
}
//lcd.print(String(seed[vanne],DEC));
//.print((String(seed[vanne],DEC)).toInt());
delay(100);
}
}
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
*/
// For V1.0 comment the other threshold and use the one below:
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup()
{
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
pinMode(A5,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A2,OUTPUT);
digitalWrite(3,HIGH);//1 OFF
digitalWrite(2,HIGH);//2 OFF
digitalWrite(1,HIGH);//3 OFF
digitalWrite(0,HIGH);//4 OFF
analogWrite(A5,255);//5 OFF
analogWrite(A4,255);//6 OFF
analogWrite(A3,255);//7 OFF
analogWrite(A2,255);//8 OFF
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Thi'Barduino"); // print a simple message
lcd.setCursor(0,1);
lcd.print("version 1.5-dev");
delay(3000);
lcd.clear();
}
void loop()
{
// put your main code here, to run repeatedly:
if(boisson <0)
{
}
else
{
//lcd.setCursor(0,1); // move cursor to second line "1" and 9 spaces over
//lcd.print(millis()/1000); // display seconds elapsed since power-up
lcd.setCursor(0,0);
lcd.print(boissons[boisson]);
if(boisson_count<10)
{
lcd.setCursor(15,0);
}
else
{
lcd.setCursor(14,0);
}
lcd.print(boisson_count);
lcd.setCursor(8,1);
lcd.print(recettes[boisson]);
lcd.setCursor(0,1); // move to the begining of the second line
}
lcd_key = read_LCD_buttons(); // read the buttons
lcd.print(lcd_key);
lcd.setCursor(15,0);
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
//lcd.print("R");
break;
}
case btnLEFT:
{
//lcd.print("L");
break;
}
case btnUP:
{
lcd.print("U");
delay(400);
if(boisson<=0){
boisson=boisson_count-1;
}else{
boisson--;
}
break;
}
case btnDOWN:
{
lcd.print("D");
delay(400);
if(boisson>=boisson_count-1)
{
boisson=0;
}
else
{
boisson++;
}
break;
}
case btnSELECT:
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("S");
distributeur(recettes[boisson]);
boisson=0;
delay(500);
lcd.clear();
break;
}
case btnNONE:
{
if(boisson==-1){
lcd.clear();
lcd.println("Selectionner votre boisson avec les fleches HAUT/BAS et valider avec SELECT");
//for (int positionCounter = 0; positionCounter < 13; positionCounter++)
//{
// // scroll one position left:
// lcd.scrollDisplayLeft();
// // wait a bit:
// delay(500);
//}
delay(1000);
//lcd.print("N");
}
break;
}
}
}
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
/* if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
*/
// For V1.0 comment the other threshold and use the one below:
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2); // start the library
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(3,HIGH);//1 OFF
digitalWrite(2,HIGH);//2 OFF
digitalWrite(1,HIGH);//3 OFF
digitalWrite(0,HIGH);//4 OFF
analogWrite(A5,255);//5 OFF
analogWrite(A4,255);//6 OFF
analogWrite(A3,255);//7 OFF
analogWrite(A2,255);//8 OFF
delay(5000);
lcd.setCursor(0,0);
lcd.print("R1:ON");
digitalWrite(3,LOW);//1 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R1:OFF");
digitalWrite(3,HIGH);//1 OFF
delay(1000);
lcd.print("R2:ON");
lcd.setCursor(0,0);
digitalWrite(2,LOW);//2 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R2:OFF");
digitalWrite(2,HIGH);//2 OFF
delay(1000);
lcd.print("R3:ON");
lcd.setCursor(0,0);
digitalWrite(1,LOW);//3 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R3:OFF");
digitalWrite(1,HIGH);//3 OFF
delay(1000);
lcd.print("R4:ON");
lcd.setCursor(0,0);
digitalWrite(0,LOW);//4 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R4:OFF");
digitalWrite(0,HIGH);//4 OFF
delay(1000);
lcd.print("R5:ON");
lcd.setCursor(0,0);
analogWrite(A5,0);//5 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R5:OFF");
analogWrite(A5,255);//5 OFF
delay(1000);
lcd.print("R6:ON");
lcd.setCursor(0,0);
analogWrite(A4,0);//6 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R6:OFF");
analogWrite(A4,255);//6 OFF
delay(1000);
lcd.setCursor(0,0);
lcd.print("R7:ON");
analogWrite(A3,0);//7 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R7:OFF");
analogWrite(A3,255);//7 OFF
delay(1000);
lcd.setCursor(0,0);
lcd.print("R8:ON");
analogWrite(A2,0);//8 ON
delay(1000);
lcd.setCursor(0,1);
lcd.print("R8:OFF");
analogWrite(A2,255);//8 OFF
delay(1000);
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
lcd.print("R");
break;
}
case btnLEFT:
{
lcd.print("L");
break;
}
case btnUP:
{
lcd.print("U");
break;
}
case btnDOWN:
{
lcd.print("D");
break;
}
case btnSELECT:
{
lcd.print("S");
break;
}
case btnNONE:
{
lcd.print("N");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment