Error messages I could use help with

I found something I ahem wanted to steal borrow but the original source was a German forum.

#include <avr/io.h>
#define F_CPU 8000000UL 
#include <util/delay.h>
int led[4]={0,1,2,3};
int count = 0;
double geschw = 1;
int verz = 10;
uint8_t LOW = 0;
uint8_t HIGH = 1;
void delayMicroseconds(uint16_t us)
{
	while(us--) {
		_delay_us(1);
	}
}  
void digitalWrite(uint8_t pin, uint8_t val)
{
  if (val == LOW) {
    PORTA &= ~(1<<pin);
  } 
  else {
    PORTA |= (1<<pin);
  }
}
//Software PWM on Attiny85 von Ernst Christensen 16.okt. 2011, angepasst von jensma
void pwm(int freq,int spin)
{
  digitalWrite(spin,HIGH);
  delayMicroseconds(1*freq);
  digitalWrite(spin,LOW);
  delayMicroseconds(1*(255-freq));
}
int main(void)
{	
  //set outputs PortA
  DDRA |= (1<<0);
  DDRA |= (1<<1);
  DDRA |= (1<<2);
  DDRA |= (1<<3);
  while(1)
  {
    for (count = 0; count < 4; count++)
    {
      for (int i = 1; i < 255; i+=1)//LED aufhellen
      {
        pwm(i,led[count]);
        delayMicroseconds(geschw);
      }
      for (int i = 1; i < 255; i+=1)//Und wieder abdunkeln
      {
        pwm(255-i,led[count]);
        delayMicroseconds(2*geschw);
      }
      verz++;
      if (verz > 20) {
        geschw *= 1.5;
      }//Das Aufhellen wird verlangsamt
      if (verz > 37) // In der letzten Phase leuchten alle LEDs noch mal auf
      {
        geschw = 1; //Ich recycle die Variablen mal, das schont den schmalen Platz
        verz = 1;
        do {
          verz++; //Tick-Value
          geschw++;
          if (verz > 50) {
            geschw+=63;
            verz = 0;
          }
          if (verz > 500) {
            delayMicroseconds(1000);
          }//N kleines Delay, das entlastet den Attiny
          for (count = 0; count < 4; count++){
            if (geschw > 254) 
            {
              digitalWrite(led[count],HIGH);
            }
            else
            {
              if (geschw > 1) 
              {
                pwm(geschw,led[count]);
              }
              else
              {
                digitalWrite(led[count],LOW);
              }
            }
          }
        }
        while (1==1); 
      }
    }
  }
}

What the code is expected is to cycle through 4 LED in varying brightness for a few seconds before stopping with all 4 LEDs lit. But without understanding German language, I couldn’t read the forum for bug fixes or something so I don’t know if I missed correction or something else.

This was meant to be used on ATtiny type chip (8 pins) and from what I can see, both io.h and delay.h are present in my Arduino folder. Error message however isn’t helping me. This is what I get:

Arduino: 1.6.7 (Windows 7), Board: “ATtiny, ATtiny85, 1 MHz (internal)”

In file included from sketch\SNES_RGBY.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:41:14: error: expected unqualified-id before numeric constant

#define LOW 0x0

^

C:\Users\HPDV7-6135dx\Documents\Arduino\SNES_RGBY\SNES_RGBY.ino:9:9: note: in expansion of macro ‘LOW’

uint8_t LOW = 0;

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected unqualified-id before numeric constant

#define HIGH 0x1

^

C:\Users\HPDV7-6135dx\Documents\Arduino\SNES_RGBY\SNES_RGBY.ino:10:9: note: in expansion of macro ‘HIGH’

uint8_t HIGH = 1;

^

C:\Users\HPDV7-6135dx\Documents\Arduino\SNES_RGBY\SNES_RGBY.ino: In function ‘void digitalWrite(uint8_t, uint8_t)’:

SNES_RGBY:20: error: ‘PORTA’ was not declared in this scope

PORTA &= ~(1 << pin);

^

SNES_RGBY:23: error: ‘PORTA’ was not declared in this scope

PORTA |= (1 << pin);

^

C:\Users\HPDV7-6135dx\Documents\Arduino\SNES_RGBY\SNES_RGBY.ino: In function ‘int main()’:

SNES_RGBY:37: error: ‘DDRA’ was not declared in this scope

DDRA |= (1 << 0);

^

exit status 1
‘PORTA’ was not declared in this scope

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

I am not quite understanding the error message and I haven’t done ATtiny before so I don’t know if I missed something. When the error came up, it was hilighting the second PORTA but not the first one listed in the code so it seems like maybe I need to declare it every single time?

Since the original source was on German forum, and I didn’t know German I couldn’t check the follow up posts for error correction and bug fixes.

Any of you know what the error code is trying to tell me?

I do have ATtiny installed in Arduino.

That code is a C program it is not for use with the Arduino IDE.

Mark

So I'll have to read the whole thing and try to translate to Arduino friendly format. Not much to change since Arduino is based on C and C++

wilykat:
So I’ll have to read the whole thing and try to translate to Arduino friendly format. Not much to change since Arduino is based on C and C++

This compiles. I used DrAzzy’s ATtiny cores. I’ve no idea if it will do what you want, though. I just had a play and did what was necessary to make it compile. (I can’t read German either.):-

int led[4] = {0, 1, 2, 3}; // Physical pins 5, 6, 7, 2 respectively.
int count = 0;
double geschw = 1;
int verz = 10;

//Software PWM on Attiny85 von Ernst Christensen 16.okt. 2011, angepasst von jensma
void pwm(int freq, int spin)
{
    digitalWrite(spin, HIGH);
    delayMicroseconds(1 * freq);
    digitalWrite(spin, LOW);
    delayMicroseconds(1 * (255 - freq));
}

int main(void)
{
    //set outputs PortB
    DDRB |= (1 << 0);
    DDRB |= (1 << 1);
    DDRB |= (1 << 2);
    DDRB |= (1 << 3);
    while (1)
    {
        for (count = 0; count < 4; count++)
        {
            for (int i = 1; i < 255; i += 1) //LED aufhellen
            {
                pwm(i, led[count]);
                delayMicroseconds(geschw);
            }
            for (int i = 1; i < 255; i += 1) //Und wieder abdunkeln
            {
                pwm(255 - i, led[count]);
                delayMicroseconds(2 * geschw);
            }
            verz++;
            if (verz > 20)
            {
                geschw *= 1.5;
            }//Das Aufhellen wird verlangsamt
            if (verz > 37) // In der letzten Phase leuchten alle LEDs noch mal auf
            {
                geschw = 1; //Ich recycle die Variablen mal, das schont den schmalen Platz
                verz = 1;
                do
                {
                    verz++; //Tick-Value
                    geschw++;
                    if (verz > 50)
                    {
                        geschw += 63;
                        verz = 0;
                    }
                    if (verz > 500)
                    {
                        delayMicroseconds(1000);
                    }//N kleines Delay, das entlastet den Attiny
                    for (count = 0; count < 4; count++)
                    {
                        if (geschw > 254)
                        {
                            digitalWrite(led[count], HIGH);
                        }
                        else
                        {
                            if (geschw > 1)
                            {
                                pwm(geschw, led[count]);
                            }
                            else
                            {
                                digitalWrite(led[count], LOW);
                            }
                        }
                    }
                }
                while (1 == 1);
            }
        }
    }
}

I think you’re probably better off just writing ‘proper’ Arduino code, with ‘setup()’ and ‘loop()’, to do software PWM yourself. It’s good practice.