Voici le code raccourci pour te montrer mon exemple; quand je passe en position 5 je reste bloqué jusqu’à la fin de programme qui fait tourner les leds du neopixel; comment faire pour que je puisse sortir du programme quand je change de position le bouton rotatif?
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#include "U8glib.h" //Inclut la librairei U8G
#include "image_bitmap.h"
//Déclaration Neopixel
Adafruit_NeoPixel NEOPIXELLAVELINGE = Adafruit_NeoPixel(24, 1, NEO_GRB + NEO_KHZ800); //neopixel lavelinge
//Cablage LCD
U8GLIB_ST7920_128X64 u8g(4,3,2, U8G_PIN_NONE); //Cablage en SPI 4-E-FIL BLANC 3-R/W-FIL ROSE 2-RS-FIL BLEU
/* Fonction permettant de redessiner TOUT l'écran */
void updateToDisp1(void);
void updateToDisp2(void);
void updateToDisp3(void);
void updateToDisp4(void);
void updateToDisp5(void);
void updateToDisp6(void);
void updateToDisp7(void);
void updateToDisp8(void);
void drawDisp1(void);
void drawDisp2(void);
void drawDisp3(void);
void drawDisp4(void);
void drawDisp5(void);
void drawDisp6(void);
void drawDisp7(void);
void drawDisp8(void);
// Fonction pour mettre à jour l'écran sur position 1
void updateToDisp1(void) {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 1
void draw(void) {
/*u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position1!");*/
u8g.drawBitmapP(0, 0, 16, 64, image_bitmap);
}
// Fonction pour mettre à jour l'écran sur position 2
void updateToDisp2(void) {
u8g.firstPage();
do {
drawDisp2();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 2
void drawDisp2(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position2!");
}
// Fonction pour mettre à jour l'écran sur position 3
void updateToDisp3(void) {
u8g.firstPage();
do {
drawDisp3();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 3
void drawDisp3(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position3!");
}
// Fonction pour mettre à jour l'écran sur position 4
void updateToDisp4(void) {
u8g.firstPage();
do {
drawDisp4();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 4
void drawDisp4(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position4!");
}
// Fonction pour mettre à jour l'écran sur position 5
void updateToDisp5(void) {
u8g.firstPage();
do {
drawDisp5();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 5
void drawDisp5(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position5!");
}
// Fonction pour mettre à jour l'écran sur position 6
void updateToDisp6(void) {
u8g.firstPage();
do {
drawDisp6();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 6
void drawDisp6(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position6!");
}
// Fonction pour mettre à jour l'écran sur position 7
void updateToDisp7(void) {
u8g.firstPage();
do {
drawDisp7();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position7
void drawDisp7(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position7!");
}
// Fonction pour mettre à jour l'écran sur position 8
void updateToDisp8(void) {
u8g.firstPage();
do {
drawDisp8();
} while( u8g.nextPage() );
}
// Fonction de dessin de l'écran position 8
void drawDisp8(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "Position8!");
}
//cablage broche bouton rotatif
const int broche_2 = 13; //rien de branché sur la broche 1
const int broche_3 = 12;
const int broche_4 = 11;
const int broche_5 = 10;
const int broche_6 = 9;
const int broche_7 = 8;
void setup() {
Serial.begin(9600);
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
NEOPIXELLAVELINGE.begin();
NEOPIXELLAVELINGE.show(); // Initialize all pixels to 'off'
//initialisation LCD
u8g.setColorIndex(1); // Affichage en mode N&B
//initialisation des broches bouton rotatif
pinMode(broche_2, OUTPUT);
pinMode(broche_3, OUTPUT);
pinMode(broche_4, INPUT_PULLUP);
pinMode(broche_5, INPUT_PULLUP);
pinMode(broche_6, INPUT_PULLUP);
pinMode(broche_7, INPUT_PULLUP);
digitalWrite(broche_2, HIGH);
digitalWrite(broche_3, HIGH);
}
void loop() {
digitalWrite (broche_2, LOW); //lecture et affichage sur le LCD de l'état du bouton rotatif position 5 6 7 8
digitalWrite (broche_3, HIGH);
if (digitalRead(broche_4) == LOW)
{
Serial.println("position5");
updateToDisp5();
theaterChaseRainbow(50);
}
if (digitalRead(broche_5) == LOW)
{
Serial.println("position6");
updateToDisp6();
}
if (digitalRead(broche_6) == LOW)
{
Serial.println("position7");
updateToDisp7();
}
if (digitalRead(broche_7) == LOW)
{
Serial.println("position8");
updateToDisp8();
}
{
digitalWrite (broche_2, HIGH); //lecture et affichage sur le LCD de l'atat du bouton rotatif position 4 3 2 1
digitalWrite (broche_3, LOW);
}
if (digitalRead(broche_4) == LOW)
{
Serial.println("position4");
updateToDisp4();
}
if (digitalRead(broche_5) == LOW)
{
Serial.println("position3");
updateToDisp3();
}
if (digitalRead(broche_6) == LOW)
{
Serial.println("position2");
updateToDisp2();
theaterChaseRainbow(50);
}
if (digitalRead(broche_7) == LOW)
{
Serial.println("position1");
updateToDisp1();
}
//Neopixel pour simuler le tambour tournant du lave linge
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < NEOPIXELLAVELINGE.numPixels(); i=i+3) {
NEOPIXELLAVELINGE.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
NEOPIXELLAVELINGE.show();
delay(wait);
for (uint16_t i=0; i < NEOPIXELLAVELINGE.numPixels(); i=i+3) {
NEOPIXELLAVELINGE.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return NEOPIXELLAVELINGE.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return NEOPIXELLAVELINGE.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return NEOPIXELLAVELINGE.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}