hi all,
normally i never had problems with void setup() to be called once - like in examples -
and then do several jobs in void loop() on arduino mega 2560
but whith this code setup() seems to be called mutiple :
<
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
// declare the lcd object for auto i2c address location
hd44780_I2Cexp lcd;
// LCD geometry
const unsigned int LCD_COLS = 20;
const unsigned int LCD_ROWS = 4;
int lcd_status = 0;
/* Substitutes HIGH/LOW for Analog-Reading
#define A_LOW 0
#define A_HIGH 255
*/
#define SHOW_DELAY 6000
#define LOOP_DELAY 20
#define COUNT_ANALOG_PINS 4
#define COUNT_ANALOG_PINS_ALL 16
#define COUNT_DIGITAL_PINS 4
#define COUNT_DIGITAL_PINS_ALL 6
const unsigned int arr_outpins_digital[COUNT_DIGITAL_PINS_ALL] = {25,27,29,
31,33,35};//- pins for Raodways to switch on/off
const String arr_outpins_texte[COUNT_DIGITAL_PINS_ALL] = {"LED FS ST1 rd","LED FS ST2 g","LED FS St2 rd",
"LED FS ST1 g","LED FS Sekt B","LED Sekt A"};
unsigned int max_pins = COUNT_DIGITAL_PINS_ALL;
void setup()
{
//Serial.begin(38400);
int lcd_status = lcd.begin(LCD_COLS, LCD_ROWS);
if (lcd_status) // non zero status means it was unsuccessful
{
// begin() failed so blink error code using the onboard LED if possible
//hd44780::fatalError(status); // does not return
}
//- Print a message to the LCD
lcd.clear();
lcd.print("led_ampel3 for mega");
delay(1000);
//-LED's init u. testen
/*
max_pins = COUNT_ANALOG_PINS_ALL;
for (unsigned int i = 0; i < max_pins; i++)
{
pinMode(arr_outpins_analog[i] , OUTPUT); // sets the digital pin [i] as output
}
*/
max_pins = COUNT_DIGITAL_PINS_ALL;
for (unsigned int i = 0; i < COUNT_DIGITAL_PINS_ALL; i++)
{
pinMode(arr_outpins_digital[i] , OUTPUT); // sets the digital pin [i] as output
}
lcd.clear();
lcd.print("Setup ready");
delay(1000);
}
void loop()
{
max_pins = COUNT_ANALOG_PINS_ALL;
for (unsigned int i = 0; i < max_pins; i++)
{
//analogWrite(arr_outpins_analog[i], A_HIGH);
digitalWrite(arr_outpins_digital[i],HIGH);
delay(LOOP_DELAY); //- Zeit zum Schreiben geben
lcd.clear();
//lcd.print("i : "+String(i)+" PIN "+String(arr_outpins_analog[i])+" "+arr_outpins_texte[i]);
lcd.print("i : "+String(i)+" PIN "+String(arr_outpins_digital[i])+" "+arr_outpins_texte[i]);
delay(SHOW_DELAY); //- Zeit zum Lesen geben
//analogWrite(arr_outpins_analog[i], A_LOW);
digitalWrite(arr_outpins_digital[i],LOW);
}
delay(LOOP_DELAY);
}
/>
the goal of the sketch is to test the function of several LED-stripes on a model-railway-tracking-desktop
all messages are shown on LCD-Display because Ardiuno per default is NOT connected to pc and IDE , but gets 7,85V from a reguklated supply.
to check what is done the sketch shows on lcd in setup first its name then the message "Setup ready" after initialisations are done
after this the loop() repeats writing to the pins and shows messages on lcd
at this moment - i was really surprised ! - the "Setup ready" appears while running
the loop !
wonder...do i have "tomatoes on the eyes" not seeing eraneous code ?
and I wonder repeatedly, that enclosing code whith backtick odr braces does Not work here !