Config menu implemented #1

This commit is contained in:
grouch 2017-04-14 23:43:53 +02:00
parent 1e7142aaab
commit 698d32e8ff
1 changed files with 34 additions and 36 deletions

View File

@ -3,19 +3,23 @@ char Ver[] = "cg140417";
#include "TimerOne.h"
#include <Encoder.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd( 9, 17, 15, 16, 14, 10);
//lcd(RS, E, D4, D5, D6, D7)
//-----------------------------------------------------------
// CONSTANTES
// PARAMETRES
//-----------------------------------------------------------
int D_Flash = 10; //Durée du flash en µs, autour de 10µs
byte D_Flash = 10; //Durée du flash en µs, autour de 10µs
const int deg_Initial = 10; //Affiché au demarrage
int Ncyl = 2;
const int Refresh = 100;
byte Ncyl = 2;
byte Refresh = 100;
//-----------------------------------------------------------
// CONSTANTES
//-----------------------------------------------------------
#define Etin 2
#define Inter 5 //Inter du codeur
@ -38,7 +42,7 @@ int unsigned long N = 0; //N en tours/mn, peut monter à plus de 44 000, 4 temp
int unsigned long Nc = 0; //Pour le calcul de N
volatile int signed deg_dem = deg_Initial; //Compteur des degrés demandés,affiché au LCD, <=0 possible
unsigned long pm = 0; //Previous millis pour Refresh LCD
int modconfig = 0; //Flag pour savoir si on est en mode config
byte modconfig = 0; //Flag pour savoir si on est en mode config
int debug = 0; //Variable pour debug, optionelle
@ -62,13 +66,26 @@ void isrFlash(){
}
void Affic_N_et_deg_dem() //Fond d'ecran inchangé,durée environ 7.5ms
{ N = Nc / T ; //Calculer N en t/mn
{ N = Nc / T; //Calculer N en t/mn
lcd.setCursor(0, 0); lcd.print(" "); //Nettoyer
lcd.setCursor(0, 0); lcd.print(N);
lcd.setCursor(0, 1); lcd.print(" "); //Nettoyer
lcd.setCursor(0, 1); lcd.print(deg_dem);
}
void Regl(byte &var, String titre){
lcd.clear();
lcd.print(titre);
Enco.write(var*4);
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
var = Enco.read()/4;
lcd.setCursor(3, 1);
lcd.print(var);
lcd.print(" ");
}
while (digitalRead(Inter) == 0); // Si on a appuyé, on attend le relachement
}
void ConfiG()
{
while (digitalRead(Inter) == 0); //toujours appuyé ? on attend
@ -79,29 +96,12 @@ void ConfiG()
while (digitalRead(Inter) == 1); //Attend un appui
while (digitalRead(Inter) == 0); // et un relachement
lcd.clear();
lcd.print("Nb cyl.");
Enco.write(Ncyl*4);
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
Ncyl = Enco.read()/4;
lcd.setCursor(3, 1);
lcd.print(Ncyl);
lcd.print(" ");
}
while (digitalRead(Inter) == 0); // Si on a appuyé, on attend le relachement
lcd.clear();
lcd.print("D Flash");
Enco.write(D_Flash*4);
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
D_Flash = Enco.read()/4
lcd.setCursor(3, 1);
lcd.print(D_Flash);
lcd.print(" ");
}
while (digitalRead(Inter) == 0);
Regl(Ncyl, "Nb cyl.");
Regl(D_Flash, "D Flash");
Regl(Refresh, "Refresh");
EEPROM.write(0, Ncyl);
EEPROM.write(1, D_Flash);
EEPROM.write(2, Refresh);
IniT();
}
@ -109,6 +109,10 @@ void IniT() {
attachInterrupt(digitalPinToInterrupt(Etin), isrEtincelle, RISING);
Timer1.attachInterrupt(isrFlash); //Timer entre Etincelle et Flash
Timer1.stop();
Ncyl = EEPROM.read(0);
D_Flash = EEPROM.read(1);
Refresh = EEPROM.read(2);
lcd.clear();
lcd.print("Strobo");
@ -129,24 +133,18 @@ void IniT() {
modconfig=0;
ConfiG();
}
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("tpm");
//lcd.print(Ncyl);
lcd.setCursor(5, 1);
lcd.print("deg");
Enco.write(deg_Initial*4);
Nc = 120000000 / Ncyl;
T = 150000;
D_deg = T / 2; //Pour le premier affichage de N
Affic_N_et_deg_dem();
}
void setup() {
Serial.begin(9600); //Pour debug
lcd.begin(8, 2);