Hi UKHeliBob,
here the full sketch.
Error code output is below.
const byte Relay = 0; //PB0
const byte LDRa = 1; //PB1
const byte LDRb = 2; //PB2
const byte LDR1 = 3; //PB3
const byte LDR2 = 4; //PB4
const byte readingLDRa = 1, readingLDRb = 2, readingLDR1 = 3, readingLDR2 = 4;
byte stateLDRa = HIGH; // state
byte stateLDRb = HIGH;
byte stateLDR1 = HIGH;
byte stateLDR2 = HIGH;
unsigned long debounceTimeLDRa; //H->L
unsigned long debounceTimeLDRb;
unsigned long debounceTimeLDR1;
unsigned long debounceTimeLDR2;
unsigned debounceDelay = 50; // H->L
unsigned onDelayLDR = 5000; // dealy time transistion L->H; from detect to undetect
byte relayState;
unsigned long onTimeLDRa;
unsigned long onTimeLDRb;
unsigned long onTimeLDR1;
unsigned long onTimeLDR2;
uint8_t pinNum[4];
// uint8_t ledArray[4];
void setup() {
for (uint8_t i = 1; i < 5; i++) {
pinMode(i, INPUT_PULLUP);
}
int pinNum[4] = {1, 2, 3, 4};
int ledArray[4] = {readingLDRa, readingLDRb, readingLDR1, readingLDR2};
for (uint8_t i = 1; i < 5; i++) {
pinMode(ledArray[i], INPUT_PULLUP);
}
pinMode(Relay, OUTPUT); //setting the pin mode to Output
digitalWrite(Relay, LOW); // relay not set, loop wired to leg a
}
void loop() {
// read LDRa and debounce + verify if state change will be from H->L
for (uint8_t i = 1; i < 5; i++) {
int ledArray[i] = digitalRead(pinNum[i]);
}
int readingLDRa = digitalRead(LDRa);
int readingLDRb = digitalRead(LDRb);
int readingLDR1 = digitalRead(LDR1);
int readingLDR2 = digitalRead(LDR2);
if (readingLDRa == LOW) {
debounceTimeLDRa = millis();
}
if ((millis() - debounceTimeLDRa) > debounceDelay || readingLDRa == LOW) {
stateLDRa = readingLDRa; // set stateLDRa = L
// outStateLDRa = readingLDRa; // set detection latch to L; train detected but not yet out of detection LDRa
}
// read LDRb and debounce + verify if state change will be from H->L
if (readingLDRb == LOW) {
debounceTimeLDRb = millis();
}
if ((millis() - debounceTimeLDRb) > debounceDelay || readingLDRb == LOW) {
stateLDRb = readingLDRb; // ->L
// outStateLDRb = readingLDRb; // set detection latch to L; train detected but not yet out of detection LDRb
}
// read LDR1 and debounce + verify if state change will be from H->L
if (readingLDR1 == LOW) {
debounceTimeLDR1 = millis();
}
if ((millis() - debounceTimeLDR1) > debounceDelay || readingLDR1 == LOW) {
stateLDR1 = readingLDR1;
// outStateLDR1 = readingLDR1; // set detection latch to L; train detected but not yet out of detection LDR1
}
// read LDR2 and debounce + verify if state change will be from H->L
if (readingLDR2 == LOW) {
debounceTimeLDR2 = millis();
}
if ((millis() - debounceTimeLDR2) > debounceDelay || readingLDR2 == LOW) {
stateLDR2 = readingLDR2;
// outStateLDR1 = readingLDR1; // set detection latch to L; train detected but not yet out of detection LDR1
}
//Delayed LDRa state change L->H, back to no detection
if (stateLDRa == LOW || readingLDRa == HIGH) {
// only execute when LDRa was LOW and changes state back to H
onTimeLDRa = millis();
if (millis() - onTimeLDRa > onDelayLDR || readingLDRa == HIGH) { // delay exectuted after L->H
stateLDRa = readingLDRa; // reset stateLDRa H
}
}
//Delayed LDRb state change L->H, back to no detection
if (stateLDRb == LOW || readingLDRb == HIGH) {
// only execute when LDRb changes state back to H
onTimeLDRb = millis();
if (millis() - onTimeLDRb > onDelayLDR || readingLDRb == HIGH) {
stateLDRb = readingLDRb; // reset stateLDRa
}
}
//Delayed LDR1 state change L->H, back to no detection
if (stateLDR1 == LOW || readingLDR1 == HIGH) {
// only execute when LDRb changes state back to H
onTimeLDR1 = millis();
if (millis() - onTimeLDR1 > onDelayLDR || readingLDR1 == HIGH) {
stateLDR1 = readingLDR1; // reset stateLDRa
}
}
//Delayed LDR2 state change L->H, back to no detection
if (stateLDR2 == LOW || readingLDR2 == HIGH) {
// only execute when LDRb changes state back to H
onTimeLDR2 = millis();
if (millis() - onTimeLDR2 > onDelayLDR || readingLDR2 == HIGH) {
stateLDR2 = readingLDR2; // reset stateLDRa
}
}
//conditions for relay output
// 1. leg a: LDRa detect, LDR1 no detect
if (stateLDRa == LOW && stateLDR1 == HIGH) //train above LDRa but not inside loop yet
{
digitalWrite(Relay, LOW);
}
// 2. leg a: LDRa detect, LDR1 also detect
if (stateLDRa == LOW && stateLDR1 == LOW) //train above LDRa but not inside loop yet
{
digitalWrite(Relay, LOW);
}
// 3. leg a: LDRa no detect, LDR1 detect (fully inside loop)
if (stateLDRa == HIGH && stateLDR1 == LOW) //train above LDRa but not inside loop yet
{
digitalWrite(Relay, LOW);
}
// 4. leg b: LDRb detect, LDR2 no detect
if (stateLDRa == LOW && stateLDR1 == HIGH) //train above LDRa but not inside loop yet
{
digitalWrite(Relay, HIGH);
}
// 5. leg b: LDRb detect, LDR2 also detect
if (stateLDRa == LOW && stateLDR1 == LOW) //train above LDRa but not inside loop yet
{
digitalWrite(Relay, HIGH);
}
// 6. leg b: LDRb no detect, LDR2 detect (fully inside loop)
if (stateLDRa == HIGH && stateLDR1 == LOW) //train above LDRa but not inside loop yet
{
digitalWrite(Relay, HIGH);
}
}
Error output:
Arduino: 1.8.13 (Windows 10), Board:"ATtiny85/25/45 (No bootloader), Enabled, CPU (CPU frequency), ATtiny85, 8 MHz (internal), EEPROM retained, B.O.D. Disabled (saves power), Enabled"
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Erik Arckens\AppData\Local\Arduino15\packages -hardware C:\Users\Erik Arckens\Google Drive\documents\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Erik Arckens\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Erik Arckens\Google Drive\documents\Arduino\libraries -fqbn=ATTinyCore:avr:attinyx5:LTO=enable,TimerClockSource=default,chip=85,clock=8internal,eesave=aenable,bod=disable,millis=enabled -ide-version=10813 -build-path C:\Users\ERIKAR~1\AppData\Local\Temp\arduino_build_448917 -warnings=default -build-cache C:\Users\ERIKAR~1\AppData\Local\Temp\arduino_cache_977379 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18 -prefs=runtime.tools.avrdude-6.3.0-arduino18.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18 -prefs=runtime.tools.micronucleus.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -prefs=runtime.tools.micronucleus-2.5-azd1b.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -verbose C:\Users\Erik Arckens\Google Drive\documents\Arduino\Digispark_modeltrain_reversing_loop_v5\Digispark_modeltrain_reversing_loop_v5.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Erik Arckens\AppData\Local\Arduino15\packages -hardware C:\Users\Erik Arckens\Google Drive\documents\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Erik Arckens\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Erik Arckens\Google Drive\documents\Arduino\libraries -fqbn=ATTinyCore:avr:attinyx5:LTO=enable,TimerClockSource=default,chip=85,clock=8internal,eesave=aenable,bod=disable,millis=enabled -ide-version=10813 -build-path C:\Users\ERIKAR~1\AppData\Local\Temp\arduino_build_448917 -warnings=default -build-cache C:\Users\ERIKAR~1\AppData\Local\Temp\arduino_cache_977379 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18 -prefs=runtime.tools.avrdude-6.3.0-arduino18.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18 -prefs=runtime.tools.micronucleus.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -prefs=runtime.tools.micronucleus-2.5-azd1b.path=C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -verbose C:\Users\Erik Arckens\Google Drive\documents\Arduino\Digispark_modeltrain_reversing_loop_v5\Digispark_modeltrain_reversing_loop_v5.ino
Using board 'attinyx5' from platform in folder: C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2
Using core 'tiny' from platform in folder: C:\Users\Erik Arckens\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2
Detecting libraries used...
"C:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=8000000L -DCLOCK_SOURCE=0 -DARDUINO=10813 -DARDUINO_AVR_ATTINYX5 -DARDUINO_ARCH_AVR -DNEOPIXELPORT=PORTB "-IC:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\cores\\tiny" "-IC:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\variants\\tinyX5" "C:\\Users\\ERIKAR~1\\AppData\\Local\\Temp\\arduino_build_448917\\sketch\\Digispark_modeltrain_reversing_loop_v5.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE
Generating function prototypes...
"C:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=8000000L -DCLOCK_SOURCE=0 -DARDUINO=10813 -DARDUINO_AVR_ATTINYX5 -DARDUINO_ARCH_AVR -DNEOPIXELPORT=PORTB "-IC:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\cores\\tiny" "-IC:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\variants\\tinyX5" "C:\\Users\\ERIKAR~1\\AppData\\Local\\Temp\\arduino_build_448917\\sketch\\Digispark_modeltrain_reversing_loop_v5.ino.cpp" -o "C:\\Users\\ERIKAR~1\\AppData\\Local\\Temp\\arduino_build_448917\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE
"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\ERIKAR~1\\AppData\\Local\\Temp\\arduino_build_448917\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Bezig met het compileren van de schets...
"C:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=attiny85 -DF_CPU=8000000L -DCLOCK_SOURCE=0 -DARDUINO=10813 -DARDUINO_AVR_ATTINYX5 -DARDUINO_ARCH_AVR -DNEOPIXELPORT=PORTB "-IC:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\cores\\tiny" "-IC:\\Users\\Erik Arckens\\AppData\\Local\\Arduino15\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\variants\\tinyX5" "C:\\Users\\ERIKAR~1\\AppData\\Local\\Temp\\arduino_build_448917\\sketch\\Digispark_modeltrain_reversing_loop_v5.ino.cpp" -o "C:\\Users\\ERIKAR~1\\AppData\\Local\\Temp\\arduino_build_448917\\sketch\\Digispark_modeltrain_reversing_loop_v5.ino.cpp.o"
C:\Users\Erik Arckens\Google Drive\documents\Arduino\Digispark_modeltrain_reversing_loop_v5\Digispark_modeltrain_reversing_loop_v5.ino: In function 'void loop()':
Digispark_modeltrain_reversing_loop_v5:70:34: error: array must be initialized with a brace-enclosed initializer
int ledArray[i] = digitalRead(pinNum[i]);
~~~~~~~~~~~^~~~~~~~~~~
exit status 1
array must be initialized with a brace-enclosed initializer