Go Down

Topic: Arduino and Railway Modelling (Read 6833 times) previous topic - next topic

johnbet

Ok will try and code tag in future.


The fade and flicker now work on separate pins as per the last revised code I sent.

I have another sketch now which is for a similar thing on an ATTiny so i would like to incorporate the fade and flicker into that. I tried copying and pasting the individual routines and adding them to void - the fade doesn't work at all - the light just switches on and off.

The Flicker seems to work but doesn't change to a constant on.

Here is the sketch i attempted

Code: [Select]


int decoderAddress = 77; // This is the decoder address, change into the number you want.
#define F0_pin 0 // Define the output pin for every Function number in use
#define F1_pin 1 // Available pin numbers: 0,1,3,4,(5 is normally reset)
#define F2_pin 3
#define F3_pin 4

#include <DCC_Decoder.h>
#define kDCC_INTERRUPT 0

byte Func[4]; //0=L4321, 1=8765, 2=CBA9, 3=F20-F13, 4=F28-F21
byte instrByte1;
int Address;
byte forw_rev=1; //0=reverse, 1=forward

boolean RawPacket_Handler(byte pktByteCount, byte* dccPacket) {
  Address=0;
  if (!bitRead(dccPacket[0],7)) { //bit7=0 -> Loc Decoder Short Address
    Address = dccPacket[0];
    instrByte1 = dccPacket[1];
  }
  else if (bitRead(dccPacket[0],6)) { //bit7=1 AND bit6=1 -> Loc Decoder Long Address
    Address = 256 * (dccPacket[0] & B00000111) + dccPacket[1];
    instrByte1 = dccPacket[2];
  }

  if (Address==decoderAddress) {
    byte instructionType = instrByte1>>5;
    switch (instructionType) {
      case 2: // Reverse speed
        forw_rev=0;
        break;
      case 3: // Forward speed
        forw_rev=1;
        break;
      case 4: // Loc Function L-4-3-2-1
        Func[0]=instrByte1&B00011111;
        break;
      case 5: // Loc Function 8-7-6-5
        if (bitRead(instrByte1,4)) {
          Func[1]=instrByte1&B00001111;
        }
        else { // Loc Function 12-11-10-9
          Func[2]=instrByte1&B00001111;
        }
        break;
    }
    // F0 is an example of two output pins that alternate based on loc forw_rev driving direction.
    if (Func[0]&B00010000) digitalWrite(F0_pin,HIGH); else digitalWrite(F0_pin,LOW);
    if (Func[0]&B00000001) digitalWrite(F1_pin,HIGH); else digitalWrite(F1_pin,LOW);
    if (Func[0]&B00000010) digitalWrite(F2_pin,HIGH); else digitalWrite(F2_pin,LOW);
    if (Func[0]&B00000100) digitalWrite(F3_pin,HIGH); else digitalWrite(F3_pin,LOW);
  }
}

void fadeF0() {
  static unsigned long lastFadeTimeF0 = 0;
  static int fadeLevelF0 = 0;

  if (millis() - lastFadeTimeF0 > 10) {
   
    lastFadeTimeF0 = millis();
   
    if (Func[1]&B00000100) {
      if (fadeLevelF0 < 255) analogWrite(F0_pin, ++fadeLevelF0);
      }
    else {
      if (fadeLevelF0 > 0) analogWrite(F0_pin, --fadeLevelF0);
    }
  }
}

void flickerF1() {

  static unsigned long startTimeF1 = 0;
  static unsigned long lastFlickerF1 = 0;
  static int stateF1 = HIGH;

  if (Func[1]&B00001000) {
    if (stateF1 == LOW) {
      startTimeF1 = millis();
      stateF1 = HIGH;
    }
    else {
      if (millis() - startTimeF1 > 3000) {
        digitalWrite(F1_pin, HIGH);
      }
      else {
        if (millis() - lastFlickerF1 > 25) {
          lastFlickerF1 = millis();
          if (random(2) == 0) digitalWrite(F1_pin, HIGH); else digitalWrite(F1_pin, LOW);
        }
      }
    }
  }
  else {
    digitalWrite(F1_pin, LOW);
    stateF1 = LOW;
  }
}

void setup() {
  DCC.SetRawPacketHandler(RawPacket_Handler);
  DCC.SetupMonitor( kDCC_INTERRUPT );
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
}

void loop() {
  DCC.loop();\
    fadeF0();
  flickerF1();
}


regards

John

PaulRB

#31
Mar 10, 2017, 08:07 pm Last Edit: Mar 10, 2017, 08:09 pm by PaulRB
Hi John, yes, I can see you have missed a few changes that need to be done. I don't know how much help you want or need, so I'll just give you the clue that the changes you need to do all relate to those binary codes in the sketch. I don't want to simply give you the answers because you are doing very well so far.

johnbet

#32
Mar 11, 2017, 12:05 pm Last Edit: Mar 11, 2017, 01:34 pm by johnbet
Hi

Yes i think I see where I went wrong. I have made the binary code in the fade and flicker routines consistant with those in the original 'instructions'

It now all works!

Code: [Select]

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//DCC Function Decoder
//JHB
//Attiny 85 Development Board
//Four Functions
//Type of Function in separate routine
//Do no forget to make sure binary code consistant with output pin!!!!!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT: GOTO lines 15 - 28 to configure some data!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int decoderAddress = 77; // This is the decoder address, change into the number you want.
#define F0_pin 0 // Define the output pin for every Function number in use
#define F1_pin 1 // Available pin numbers: 0,1,3,4,(5 is normally reset)
#define F2_pin 3
#define F3_pin 4

#include <DCC_Decoder.h>
#define kDCC_INTERRUPT 0

byte Func[4]; //0=L4321, 1=8765, 2=CBA9, 3=F20-F13, 4=F28-F21
byte instrByte1;
int Address;
byte forw_rev=1; //0=reverse, 1=forward

boolean RawPacket_Handler(byte pktByteCount, byte* dccPacket) {
  Address=0;
  if (!bitRead(dccPacket[0],7)) { //bit7=0 -> Loc Decoder Short Address
    Address = dccPacket[0];
    instrByte1 = dccPacket[1];
  }
  else if (bitRead(dccPacket[0],6)) { //bit7=1 AND bit6=1 -> Loc Decoder Long Address
    Address = 256 * (dccPacket[0] & B00000111) + dccPacket[1];
    instrByte1 = dccPacket[2];
  }

  if (Address==decoderAddress) {
    byte instructionType = instrByte1>>5;
    switch (instructionType) {
      case 2: // Reverse speed
        forw_rev=0;
        break;
      case 3: // Forward speed
        forw_rev=1;
        break;
      case 4: // Loc Function L-4-3-2-1
        Func[0]=instrByte1&B00011111;
        break;
      case 5: // Loc Function 8-7-6-5
        if (bitRead(instrByte1,4)) {
          Func[1]=instrByte1&B00001111;
        }
        else { // Loc Function 12-11-10-9
          Func[2]=instrByte1&B00001111;
        }
        break;
    }
    // F0 is an example of two output pins that alternate based on loc forw_rev driving direction.
    //if (Func[0]&B00010000) digitalWrite(F0_pin,HIGH); else digitalWrite(F0_pin,LOW);
    //if (Func[0]&B00000001) digitalWrite(F1_pin,HIGH); else digitalWrite(F1_pin,LOW);
    if (Func[0]&B00000010) digitalWrite(F2_pin,HIGH); else digitalWrite(F2_pin,LOW);
    if (Func[0]&B00000100) digitalWrite(F3_pin,HIGH); else digitalWrite(F3_pin,LOW);
  }
}

void fadeF0() {
  static unsigned long lastFadeTimeF0 = 0;
  static int fadeLevelF0 = 0;

  if (millis() - lastFadeTimeF0 > 10) {
  
    lastFadeTimeF0 = millis();
  
    if (Func[0]&B00010000) {
      if (fadeLevelF0 < 255) analogWrite(F0_pin, ++fadeLevelF0);
      }
    else {
      if (fadeLevelF0 > 0) analogWrite(F0_pin, --fadeLevelF0);
    }
  }
}

void flickerF1() {

  static unsigned long startTimeF1 = 0;
  static unsigned long lastFlickerF1 = 0;
  static int stateF1 = HIGH;

  if (Func[0]&B00000001) {
    if (stateF1 == LOW) {
      startTimeF1 = millis();
      stateF1 = HIGH;
    }
    else {
      if (millis() - startTimeF1 > 3000) {
        digitalWrite(F1_pin, HIGH);
      }
      else {
        if (millis() - lastFlickerF1 > 25) {
          lastFlickerF1 = millis();
          if (random(2) == 0) digitalWrite(F1_pin, HIGH); else digitalWrite(F1_pin, LOW);
        }
      }
    }
  }
  else {
    digitalWrite(F1_pin, LOW);
    stateF1 = LOW;
  }
}

void setup() {
  DCC.SetRawPacketHandler(RawPacket_Handler);
  DCC.SetupMonitor( kDCC_INTERRUPT );
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
}

void loop() {
  DCC.loop();
    fadeF0();
  flickerF1();
}


So from my original start point I am almost there.

Now need to sort out 'sub-routines' for flash, double flash and strobe without using delay and also would like to control brightness of led by using analogueWrite on PWM pins.

I will try writing each  - one at a time - and see how I get on.

Once again many thanks for your patience and guidance.

PS

Have sorted the analogwrite out so just the flash and double flash now, but have struggled with those - any help you can give would be appreciated.

PaulRB

Post your attempt. And explain again exactly how you want the flashing to go.

johnbet

Hi

The 'flashing' sequences I am trying to achieve are as follows.

1. LED on for period A
    LED off for period B
    LED on for Period A
    LED off for Period B   and so on

2. LED on for Period A
    LED off for Period B
    LED on for period C
    LED on for period D
    then Repeat

3. LED on with random on/off  as per the flicker start but staying flickering.

I am aware that DELAY shouldn't be used and that millis ids probably the way to go - but having studied a millis sketch for blink without delay I am struggling to interpret how to include in the sketches I already have.

Once I have these I have all the sketches I need.

Once again many thanks.

PaulRB

#35
Mar 12, 2017, 12:44 pm Last Edit: Mar 12, 2017, 12:50 pm by PaulRB
Quote
LED on for period D
Did you mean "off"?

Quote
I am struggling to interpret how to include in the sketches I already have
Look at the two sections of code I gave you. They were written using the same principles as "blink without delay". They both use millis() rather than delay(). They have some things in common:
  • An unsigned long variable which takes a snapshot of millis() at the point where the DCC command to switch on/off is received. This can be used later and compared to millis() to see how much time has elapsed.
  • Some kind of "state" variable(s) that record the current position in a sequence of actions (rather than writing that list of actions as lines of code with delay() between them)
  • Each function has to be called from loop() so that it gets a chance to check millis() to see if it is time for the next action to be taken. But most times these function get called, they compare millis() with a snapshot from a previous call, but it is not yet time to do anything, so they do nothing and loop() carries on.
  • Some variables in the functions are declared as "static". This means they do not loose their values from one call to the next, which is obviously important for states and time snapshots

The way I like to think of "blink without delay" style code is to imagine you are performing the actions yourself, and measuring the passage of time with a stopwatch, in seconds (rather than milliseconds!). But you are very busy and are having to do many things at once, and you are by yourself with no-one to help you. Also you have a short memory, so you also have a notebook and pen, to make notes on what time you take actions and what action you need to perform next and so on. You can never wait in one place for long, performing a long sequence of actions and standing around waiting for time to pass before you can perform the next action. You have to move quickly on to your other responsibilities. So you make notes about what you did and when, then move on. But you come back to each task frequently, check the time, read your notes, take what actions you can, and move on again.

I know you would like me to write the last bits of code you need, but I would prefer to teach you to fish, not just give you a fish.

johnbet

I understand what you are saying but my coding knowledge is limited and these millis functions take some grasping for me.

I have had a go at incorporating what I believe is a standard millis 'blibk' sketch into my sketch without success.

I cannot pretend I understand the logic of it but I have tried to stick to what seems logical.

Suffice to say don't appear to be getting past go.
Code: [Select]

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//DCC Function Decoder
//JHB
//Attiny 85 Development Board
//Four Functions
//Type of Function in separate routine
//Note - PWM/analogWrite only available on Pins 0 (F0),1 (F1) and 4 (F3)
//Do no forget to make sure binary code consistant with output pin!!!!!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT: GOTO lines 15 - 19 to configure some data!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int decoderAddress = 77; // This is the decoder address, change into the number you want.
#define F0_pin 0 // Define the output pin for every Function number in use
#define F1_pin 1 // Available pin numbers: 0,1,3,4,(5 is normally reset)
#define F2_pin 3 // Pins 0, 1 and 4 are PWM and can be used for analogWrite
#define F3_pin 4

#include <DCC_Decoder.h>
#define kDCC_INTERRUPT 0

byte Func[4]; //0=L4321, 1=8765, 2=CBA9, 3=F20-F13, 4=F28-F21
byte instrByte1;
int Address;
byte forw_rev=1; //0=reverse, 1=forward

boolean RawPacket_Handler(byte pktByteCount, byte* dccPacket) {
  Address=0;
  if (!bitRead(dccPacket[0],7)) { //bit7=0 -> Loc Decoder Short Address
    Address = dccPacket[0];
    instrByte1 = dccPacket[1];
  }
  else if (bitRead(dccPacket[0],6)) { //bit7=1 AND bit6=1 -> Loc Decoder Long Address
    Address = 256 * (dccPacket[0] & B00000111) + dccPacket[1];
    instrByte1 = dccPacket[2];
  }

  if (Address==decoderAddress) {
    byte instructionType = instrByte1>>5;
    switch (instructionType) {
      case 2: // Reverse speed
        forw_rev=0;
        break;
      case 3: // Forward speed
        forw_rev=1;
        break;
      case 4: // Loc Function L-4-3-2-1
        Func[0]=instrByte1&B00011111;
        break;
      case 5: // Loc Function 8-7-6-5
        if (bitRead(instrByte1,4)) {
          Func[1]=instrByte1&B00001111;
        }
        else { // Loc Function 12-11-10-9
          Func[2]=instrByte1&B00001111;
        }
        break;
    }
    //if (Func[0]&B00010000) digitalWrite(F0_pin,HIGH); else digitalWrite(F0_pin,LOW);
    //if (Func[0]&B00000001) digitalWrite(F1_pin,HIGH); else digitalWrite(F1_pin,LOW);
    //if (Func[0]&B00000010) digitalWrite(F2_pin,HIGH); else digitalWrite(F2_pin,LOW);
    if (Func[0]&B00000100) analogWrite(F3_pin, 100); else analogWrite(F3_pin, 0);
  }
}

void fadeF0() {
  static unsigned long lastFadeTimeF0 = 0;
  static int fadeLevelF0 = 0;

  if (millis() - lastFadeTimeF0 > 10) {
   
    lastFadeTimeF0 = millis();
   
    if (Func[0]&B00010000) {
      if (fadeLevelF0 < 255) analogWrite(F0_pin, ++fadeLevelF0);
      }
    else {
      if (fadeLevelF0 > 0) analogWrite(F0_pin, --fadeLevelF0);
    }
  }
}

void flickerF1() {

  static unsigned long startTimeF1 = 0;
  static unsigned long lastFlickerF1 = 0;
  static int stateF1 = HIGH;

  if (Func[0]&B00000001) {
    if (stateF1 == LOW) {
      startTimeF1 = millis();
      stateF1 = HIGH;
    }
    else {
      if (millis() - startTimeF1 > 3000) {
        digitalWrite(F1_pin, HIGH);
      }
      else {
        if (millis() - lastFlickerF1 > 25) {
          lastFlickerF1 = millis();
          if (random(2) == 0) digitalWrite(F1_pin, HIGH); else digitalWrite(F1_pin, LOW);
        }
      }
    }
  }
  else {
    digitalWrite(F1_pin, LOW);
    stateF1 = LOW;
  }
}

void blinkF2() {

  static int stateF2 = LOW;           
  unsigned long previousMillis = 0;       
  const long interval = 1000;           

  unsigned long currentMillis = millis();

  if (Func[0]&B00000010) {
    if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    if (stateF2 == LOW) {
      stateF2 = HIGH;
    } else {
      stateF2 = LOW;
    }

    digitalWrite(F2_pin,LOW);
    } 

void setup() {
  DCC.SetRawPacketHandler(RawPacket_Handler);
  DCC.SetupMonitor( kDCC_INTERRUPT );
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

}

  void loop() {
  DCC.loop();
  fadeF0();
  flickerF1();
  blinkF2();
}


Thank you

PaulRB

#37
Mar 12, 2017, 04:58 pm Last Edit: Mar 12, 2017, 05:00 pm by PaulRB
Have a little more faith in yourself!

I can see one mistake, on this line:
Code: [Select]
   digitalWrite(F2_pin,LOW);
Fix that, it should work.

Tip: use Auto Format from the Tools menu in the IDE. That will correct your indentation, which apart from making the code easier to read, makes it easier to spot when you have a { or } in the wrong place.

johnbet

Hi

The only thing I can think of ammending there is changing Low to High  - unable to test if it works as am getting an error message when compiling.

Just before the final void loop on line 146 the error message is saying

'a function-definition is not allowed here before the '{' token' ??

Regards

John


GrooveFlotilla

Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

johnbet

Sorry

here it is

Code: [Select]

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//DCC Function Decoder
//JHB
//Attiny 85 Development Board
//Four Functions
//Type of Function in separate routine
//Note - PWM/analogWrite only available on Pins 0 (F0),1 (F1) and 4 (F3)
//Do no forget to make sure binary code consistant with output pin!!!!!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT: GOTO lines 15 - 19 to configure some data!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int decoderAddress = 77; // This is the decoder address, change into the number you want.
#define F0_pin 0 // Define the output pin for every Function number in use
#define F1_pin 1 // Available pin numbers: 0,1,3,4,(5 is normally reset)
#define F2_pin 3 // Pins 0, 1 and 4 are PWM and can be used for analogWrite
#define F3_pin 4

#include <DCC_Decoder.h>
#define kDCC_INTERRUPT 0

byte Func[4]; //0=L4321, 1=8765, 2=CBA9, 3=F20-F13, 4=F28-F21
byte instrByte1;
int Address;
byte forw_rev = 1; //0=reverse, 1=forward

boolean RawPacket_Handler(byte pktByteCount, byte* dccPacket) {
  Address = 0;
  if (!bitRead(dccPacket[0], 7)) { //bit7=0 -> Loc Decoder Short Address
    Address = dccPacket[0];
    instrByte1 = dccPacket[1];
  }
  else if (bitRead(dccPacket[0], 6)) { //bit7=1 AND bit6=1 -> Loc Decoder Long Address
    Address = 256 * (dccPacket[0] & B00000111) + dccPacket[1];
    instrByte1 = dccPacket[2];
  }

  if (Address == decoderAddress) {
    byte instructionType = instrByte1 >> 5;
    switch (instructionType) {
      case 2: // Reverse speed
        forw_rev = 0;
        break;
      case 3: // Forward speed
        forw_rev = 1;
        break;
      case 4: // Loc Function L-4-3-2-1
        Func[0] = instrByte1 & B00011111;
        break;
      case 5: // Loc Function 8-7-6-5
        if (bitRead(instrByte1, 4)) {
          Func[1] = instrByte1 & B00001111;
        }
        else { // Loc Function 12-11-10-9
          Func[2] = instrByte1 & B00001111;
        }
        break;
    }
    //if (Func[0]&B00010000) digitalWrite(F0_pin,HIGH); else digitalWrite(F0_pin,LOW);
    //if (Func[0]&B00000001) digitalWrite(F1_pin,HIGH); else digitalWrite(F1_pin,LOW);
    //if (Func[0]&B00000010) digitalWrite(F2_pin, HIGH); else digitalWrite(F2_pin, LOW);
    if (Func[0]&B00000100) analogWrite(F3_pin, 100); else analogWrite(F3_pin, 0);
  }
}

void fadeF0() {
  static unsigned long lastFadeTimeF0 = 0;
  static int fadeLevelF0 = 0;

  if (millis() - lastFadeTimeF0 > 10) {

    lastFadeTimeF0 = millis();

    if (Func[0]&B00010000) {
      if (fadeLevelF0 < 255) analogWrite(F0_pin, ++fadeLevelF0);
    }
    else {
      if (fadeLevelF0 > 0) analogWrite(F0_pin, --fadeLevelF0);
    }
  }
}

void flickerF1() {

  static unsigned long startTimeF1 = 0;
  static unsigned long lastFlickerF1 = 0;
  static int stateF1 = HIGH;

  if (Func[0]&B00000001) {
    if (stateF1 == LOW) {
      startTimeF1 = millis();
      stateF1 = HIGH;
    }
    else {
      if (millis() - startTimeF1 > 3000) {
        digitalWrite(F1_pin, HIGH);
      }
      else {
        if (millis() - lastFlickerF1 > 25) {
          lastFlickerF1 = millis();
          if (random(2) == 0) digitalWrite(F1_pin, HIGH); else digitalWrite(F1_pin, LOW);
        }
      }
    }
  }
  else {
    digitalWrite(F1_pin, LOW);
    stateF1 = LOW;
  }
}

void blinkF2() {

  static int stateF2 = LOW;
  unsigned long previousMillis = 0;
  const long interval = 1000;

  unsigned long currentMillis = millis();

  if (Func[0]&B00000010) {
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;

      if (stateF2 == LOW) {
        stateF2 = HIGH;
      } else {
        stateF2 = LOW;
      }

      digitalWrite(F2_pin, HIGH);
    }

-definition
    void setup() {
      DCC.SetRawPacketHandler(RawPacket_Handler);
      DCC.SetupMonitor( kDCC_INTERRUPT );
      pinMode(0, OUTPUT);
      pinMode(1, OUTPUT);
      pinMode(3, OUTPUT);
      pinMode(4, OUTPUT);

    }

void loop() {
      DCC.loop();
      fadeF0();
      flickerF1();
      blinkF2();
    }

GrooveFlotilla

Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

johnbet

it was in the non verbose error message - here is the verbose error message.

Arduino: 1.8.1 (Mac OS X), Board: "Digispark (Default - 16.5mhz)"

/Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -hardware /Users/johnbet/Library/Arduino15/packages -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/johnbet/Library/Arduino15/packages -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/johnbet/Documents/Arduino/libraries -fqbn=digistump:avr:digispark-tiny -ide-version=10801 -build-path /var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.micronucleus.path=/Users/johnbet/Library/Arduino15/packages/digistump/tools/micronucleus/2.0a4 -prefs=runtime.tools.avr-gcc.path=/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5 -verbose /var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_368482/sketch_mar13a.ino
/Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -hardware /Users/johnbet/Library/Arduino15/packages -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/johnbet/Library/Arduino15/packages -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/johnbet/Documents/Arduino/libraries -fqbn=digistump:avr:digispark-tiny -ide-version=10801 -build-path /var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.micronucleus.path=/Users/johnbet/Library/Arduino15/packages/digistump/tools/micronucleus/2.0a4 -prefs=runtime.tools.avr-gcc.path=/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5 -verbose /var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_368482/sketch_mar13a.ino
Using board 'digispark-tiny' from platform in folder: /Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7
Using core 'tiny' from platform in folder: /Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7
Detecting libraries used...
"/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16500000L -DARDUINO=10801 -DARDUINO_AVR_DIGISPARK -DARDUINO_ARCH_AVR  "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny" "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/variants/digispark" "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/sketch/sketch_mar13a.ino.cpp" -o "/dev/null"
"/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16500000L -DARDUINO=10801 -DARDUINO_AVR_DIGISPARK -DARDUINO_ARCH_AVR  "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny" "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/variants/digispark" "-I/Users/johnbet/Documents/Arduino/libraries/DCC_Decoder" "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/sketch/sketch_mar13a.ino.cpp" -o "/dev/null"
"/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16500000L -DARDUINO=10801 -DARDUINO_AVR_DIGISPARK -DARDUINO_ARCH_AVR  "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny" "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/variants/digispark" "-I/Users/johnbet/Documents/Arduino/libraries/DCC_Decoder" "/Users/johnbet/Documents/Arduino/libraries/DCC_Decoder/DCC_Decoder.cpp" -o "/dev/null"
Generating function prototypes...
"/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections  -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16500000L -DARDUINO=10801 -DARDUINO_AVR_DIGISPARK -DARDUINO_ARCH_AVR  "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny" "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/variants/digispark" "-I/Users/johnbet/Documents/Arduino/libraries/DCC_Decoder" "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/sketch/sketch_mar13a.ino.cpp" -o "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/preproc/ctags_target_for_gcc_minus_e.cpp"
"/Applications/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/preproc/ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"/Users/johnbet/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=attiny85 -DF_CPU=16500000L -DARDUINO=10801 -DARDUINO_AVR_DIGISPARK -DARDUINO_ARCH_AVR  "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny" "-I/Users/johnbet/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/variants/digispark" "-I/Users/johnbet/Documents/Arduino/libraries/DCC_Decoder" "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/sketch/sketch_mar13a.ino.cpp" -o "/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_build_720377/sketch/sketch_mar13a.ino.cpp.o"
sketch_mar13a:1: error: expected unqualified-id before '[' token
 
Code: [Select]

 ^
/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_368482/sketch_mar13a.ino: In function 'boolean RawPacket_Handler(byte, byte*)':
sketch_mar13a:41: error: 'decoderAddress' was not declared in this scope
   if (Address == decoderAddress) {
                  ^
/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_368482/sketch_mar13a.ino: In function 'void blinkF2()':
sketch_mar13a:136: error: 'definition' was not declared in this scope
     -definition
      ^
sketch_mar13a:137: error: expected ';' before 'void'
     void setup() {
     ^
sketch_mar13a:147: error: a function-definition is not allowed here before '{' token
     void loop() {
                 ^
sketch_mar13a:153: error: expected identifier before '/' token
     [ / code]
       ^
/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_368482/sketch_mar13a.ino: In lambda function:
sketch_mar13a:153: error: expected '{' at end of input
     [ / code]
             ^
/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_368482/sketch_mar13a.ino: In function 'void blinkF2()':
sketch_mar13a:153: error: expected ';' at end of input
sketch_mar13a:153: error: expected '}' at end of input
sketch_mar13a:153: error: expected '}' at end of input
Using library DCC_Decoder in folder: /Users/johnbet/Documents/Arduino/libraries/DCC_Decoder (legacy)
exit status 1
expected unqualified-id before '[' token


GrooveFlotilla

The "-definition" was in your code. If you look at the error messages,  you'll see the compiler barfed on it.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

johnbet

I spotted that and removed it but am still getting this error message.

the '{' token it is referring to is the one before void loop in line 145


Arduino: 1.8.1 (Mac OS X), Board: "Digispark (Default - 16.5mhz)"

/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_994488/sketch_mar13a.ino: In function 'void blinkF2()':
sketch_mar13a:136: error: a function-definition is not allowed here before '{' token
     void setup() {
                  ^
sketch_mar13a:146: error: a function-definition is not allowed here before '{' token
     void loop() {
                 ^
sketch_mar13a:152: error: expected identifier before '/' token
     [ / code]
       ^
/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_994488/sketch_mar13a.ino: In lambda function:
sketch_mar13a:152: error: expected '{' at end of input
     [ / code]
             ^
/var/folders/p6/t6t61z056n5072zf7xn17t940000gn/T/arduino_modified_sketch_994488/sketch_mar13a.ino: In function 'void blinkF2()':
sketch_mar13a:152: error: expected ';' at end of input
sketch_mar13a:152: error: expected '}' at end of input
sketch_mar13a:152: error: expected '}' at end of input
exit status 1
a function-definition is not allowed here before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Go Up