je présente mon problème, probablement du a mon peu d’expérience en programmation c j’essaie de modifier des programmes arduino faits par d’autres personnes pour utiliser mon LCD sheild, j’ai tout le matériel pour faire ce projet un « 'box joint jig arduino »' le lien de l'auteur http://tobiasmuthesius.net/2012/06/arduino-controlled-table-saw-box-joint-jig/
je suis incapable d’intégrer les entrées sans avoir d’erreur j’aimerais bien voir ce que je ne fais pas correctement.
voilà le code de mon shield :
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
/*******************************************************
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
********************************************************/
// 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 < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) 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()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Push the buttons"); // print a simple message
}
void loop()
{
lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over
lcd.print(millis()/1000); // display seconds elapsed since power-up
lcd.setCursor(0,1); // move to the begining of the second line
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("RIGHT ");
break;
}
case btnLEFT:
{
lcd.print("LEFT ");
break;
}
case btnUP:
{
lcd.print("UP ");
break;
}
case btnDOWN:
{
lcd.print("DOWN ");
break;
}
case btnSELECT:
{
lcd.print("SELECT");
break;
}
case btnNONE:
{
lcd.print("NONE ");
break;
}
}
}
voilà le code de mon projet :
#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <Button.h> //https://github.com/carlynorama/Arduino-Library-Button
#include <AccelStepper.h> //http://www.open.com.au/mikem/arduino/AccelStepper/
#define STEPS_MM 486
#define MAX_SPEED 800
#define ACCELERATION 4000
#define ZERO_SPEED 400
#define MODE_CUT 0
#define MODE_ZERO 1
#define MODE_SET_BLADE_WIDTH 2
#define MODE_SET_BLADE_ZERO 3
AccelStepper stepper(1, 3, 2);
LiquidCrystal lcd(9, 8, 13, 12, 11, 10);
Button zero(7, LOW);
Button up(6, LOW);
Button ok(5, LOW);
Button down(4, LOW);
boolean changed = false;
int mode = 1;
int cutstep = 0;
float bladewidth = 0;
float bladezero = 10;
boolean zeromove = false;
/**************************************************************/
void setup(){
Serial.begin(9600);
Serial.println("ACTSBJJ");
stepper.setMaxSpeed(MAX_SPEED);
stepper.setAcceleration(ACCELERATION);
lcd.begin(16, 2);
lcd.print("ACTSBJJ");
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(1000);
readBladeWidthFromEEPROM();
readBladeZeroFromEEPROM();
displayMode();
}
//---------------------
void loop(){
zero.listen();
up.listen();
ok.listen();
down.listen();
if(zero.onPress()) handleZero();
if(zeromove){
stepper.runSpeed();
return;
}
if(stepper.run()) return;
if(ok.onPress()) handleOk();
if(up.onPress()) handleUp();
if(down.onPress()) handleDown();
if(up.isHold()) handleUpHold();
if(down.isHold()) handleDownHold();
}
//---------------------
void moveTo(float mmpos){
stepper.moveTo(mmpos * STEPS_MM);
}
void moveStep(){
moveTo(cutstep*bladewidth+bladezero);
}
/**************************************************************/
void handleZero(){
zeromove = false;
stepper.setCurrentPosition(0);
moveTo(bladezero);
cutstep = 0;
displayMode();
}
void handleOk(){
if(mode == MODE_SET_BLADE_WIDTH && changed) writeBladeWidthToEEPROM();
if(mode == MODE_SET_BLADE_ZERO && changed) writeBladeZeroToEEPROM();
changed = false;
mode = (mode+1)%4;
displayMode();
}
//---------------------
void handleUp(){
switch(mode){
case MODE_CUT:
cutstep ++;
moveStep();
break;
case MODE_ZERO:
break;
case MODE_SET_BLADE_WIDTH:
bladewidth += 0.01;
break;
case MODE_SET_BLADE_ZERO:
bladezero += 0.01;
moveStep();
break;
}
changed = true;
displayUpdate();
}
//---------------------
void handleDown(){
switch(mode){
case MODE_CUT:
if(cutstep > 0) cutstep --;
moveStep();
break;
case MODE_ZERO:
stepper.setSpeed(-ZERO_SPEED);
zeromove = true;
break;
case MODE_SET_BLADE_WIDTH:
if(bladewidth > 0) bladewidth -= 0.01;
break;
case MODE_SET_BLADE_ZERO:
if(bladezero > 2) bladezero -= 0.01;
moveStep();
break;
}
changed = true;
displayUpdate();
}
//---------------------
void handleUpHold(){
switch(mode){
case MODE_SET_BLADE_WIDTH:
bladewidth += 0.01;
break;
case MODE_SET_BLADE_ZERO:
bladezero += 0.01;
moveStep();
break;
}
changed = true;
displayUpdate();
}
//---------------------
void handleDownHold(){
switch(mode){
case MODE_SET_BLADE_WIDTH:
if(bladewidth > 0) bladewidth -= 0.01;
break;
case MODE_SET_BLADE_ZERO:
if(bladezero > 2) bladezero -= 0.01;
moveStep();
break;
}
changed = true;
displayUpdate();
}
//---------------------
void displayMode(){
lcd.clear();
switch(mode){
case MODE_CUT:
lcd.print("Cut");
lcd.setCursor(0, 1);
lcd.print("Step: ");
lcd.print(cutstep);
break;
case MODE_ZERO:
lcd.print("Set zero");
lcd.setCursor(0, 1);
lcd.print("> Press down");
break;
case MODE_SET_BLADE_WIDTH:
lcd.print("Blade width");
lcd.setCursor(0, 1);
lcd.print(bladewidth);
lcd.print(" mm");
break;
case MODE_SET_BLADE_ZERO:
lcd.print("Blade zero");
lcd.setCursor(0, 1);
lcd.print(bladezero);
lcd.print(" mm");
break;
}
}
//---------------------
void displayUpdate(){
switch(mode){
case MODE_CUT:
lcd.setCursor(6, 1);
lcd.print(cutstep);
lcd.print(" ");
break;
case MODE_ZERO:
if(zeromove){
lcd.clear();
lcd.print("Setting zero...");
}
break;
case MODE_SET_BLADE_WIDTH:
lcd.setCursor(0, 1);
lcd.print(bladewidth);
lcd.print(" mm ");
break;
case MODE_SET_BLADE_ZERO:
lcd.setCursor(0, 1);
lcd.print(bladezero);
lcd.print(" mm ");
break;
}
}
/**************************************************************/
void readBladeWidthFromEEPROM(){
int b = (int)EEPROM.read(0) << 8 | (int)EEPROM.read(1);
bladewidth = (float)b/100;
}
void writeBladeWidthToEEPROM(){
int b = bladewidth*100;
EEPROM.write(0, (byte)(b >> 8));
EEPROM.write(1, (byte)b);
}
//---------------------
void readBladeZeroFromEEPROM(){
int b = (int)EEPROM.read(2) << 8 | (int)EEPROM.read(3);
bladezero = max((float)b/100, 2);
}
void writeBladeZeroToEEPROM(){
int b = bladezero*100;
EEPROM.write(2, (byte)(b >> 8));
EEPROM.write(3, (byte)b);
}
merci de votre aide