Pages: [1]   Go Down
Author Topic: Getting a strange error  (Read 188 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote this code for the Uno but switched over to the Due. It compiles and runs fine on the Uno but for the Due it gives me this error:  

Quote
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/Arduino.h:203,
                 from arduino_DAC.ino:10:
C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/USB/USBCore.h:208: error: expected unqualified-id before numeric constant

Here is the code:

Code:
#define d1 1
#define d2 2
#define d3 3
#define d4 4
#define d5 5
#define d6 6
#define d7 7
#define d8 8

void setup()
{
  pinMode(d1, OUTPUT);
  pinMode(d2, OUTPUT);
  pinMode(d3, OUTPUT);
  pinMode(d4, OUTPUT);
  pinMode(d5, OUTPUT);
  pinMode(d6, OUTPUT);
  pinMode(d7, OUTPUT);
  pinMode(d8, OUTPUT);
}


void loop(){
  for(int i = 0; i < 256; i++){
    
    if( (i%2) == 0){
      digitalWrite(d1, LOW);
    }
    if((i%2) == 1){
      digitalWrite(d1, HIGH);
    }
    if( (i/2)%2 == 0){
      digitalWrite(d2, LOW);
    }
    if( (i/2)%2 == 1){
      digitalWrite(d2, HIGH);
    }
    if( (i/4)%2 == 0){
      digitalWrite(d3, LOW);
    }
    if( (i/4)%2 == 1){
      digitalWrite(d3, HIGH);
    }
    if( (i/8)%2 == 0){
      digitalWrite(d4, LOW);
    }
    if( (i/8)%2 == 1){
      digitalWrite(d4, HIGH);
    }
    if( (i/16)%2 == 0){
      digitalWrite(d5, LOW);
    }
    if( (i/16)%2 == 1){
      digitalWrite(d5, HIGH);
    }
    if( (i/32)%2 == 0){
      digitalWrite(d6, LOW);
    }
    if( (i/32)%2 == 1){
      digitalWrite(d6, HIGH);
    }
    if( (i/64)%2 == 0){
      digitalWrite(d7, LOW);
    }
    if( (i/64)%2 == 1){
      digitalWrite(d7, HIGH);
    }
    if( (i/128)%2 == 0){
      digitalWrite(d8, LOW);
    }
    if( (i/128)%2 == 1){
      digitalWrite(d8, HIGH);
    }
    delay(1);
  }
  for(int i = 254; i >= 0; i--){
    
    if( (i%2) == 0){
      digitalWrite(d1, LOW);
    }
    if((i%2) == 1){
      digitalWrite(d1, HIGH);
    }
    if( (i/2)%2 == 0){
      digitalWrite(d2, LOW);
    }
    if( (i/2)%2 == 1){
      digitalWrite(d2, HIGH);
    }
    if( (i/4)%2 == 0){
      digitalWrite(d3, LOW);
    }
    if( (i/4)%2 == 1){
      digitalWrite(d3, HIGH);
    }
    if( (i/8)%2 == 0){
      digitalWrite(d4, LOW);
    }
    if( (i/8)%2 == 1){
      digitalWrite(d4, HIGH);
    }
    if( (i/16)%2 == 0){
      digitalWrite(d5, LOW);
    }
    if( (i/16)%2 == 1){
      digitalWrite(d5, HIGH);
    }
    if( (i/32)%2 == 0){
      digitalWrite(d6, LOW);
    }
    if( (i/32)%2 == 1){
      digitalWrite(d6, HIGH);
    }
    if( (i/64)%2 == 0){
      digitalWrite(d7, LOW);
    }
    if( (i/64)%2 == 1){
      digitalWrite(d7, HIGH);
    }
    if( (i/128)%2 == 0){
      digitalWrite(d8, LOW);
    }
    if( (i/128)%2 == 1){
      digitalWrite(d8, HIGH);
    }
    delay(1);
  }
}

Does anyone know whats wrong? Is it the mod?
Logged

Offline Offline
Edison Member
*
Karma: 27
Posts: 2033
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is complaining about line 208 in the h file,  supposedly.

Look at the h file in an editor which has some way of counting lines.
Logged

Offline Offline
Edison Member
*
Karma: 27
Posts: 2033
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And that is pretty cretinous code.   Does the keyword "else"  not work in DUE C++ ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know its ugly but it works and does what I need it to do. This is header file generating the error:

Code:
uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
{
    uint32_t n;
int r = len;
const uint8_t* data = (const uint8_t*)d;

    if (!_usbConfiguration)
    {
    TRACE_CORE(printf("pb conf\n\r");)
return -1;
    }

while (len)
{
        if(ep==0) n = EP0_SIZE;
        else n =  EPX_SIZE;
if (n > len)
n = len;
len -= n;

UDD_Send(ep & 0xF, data, n);
data += n;
    }
//TXLED1; // light the TX LED
//TxLEDPulse = TX_RX_LED_PULSE_MS;
return r;
}

line 208 is the "return r" line. This is incomprehensible to me, I dont understand what the problem is.
Logged

Cincinnati, OH
Online Online
Sr. Member
****
Karma: 15
Posts: 453
I'm not bossy...I just know what you should be doing.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, the original post is not the code because there is no #include preprocessor directive in it. When I compile the header file you posted, the compiler tells me _usbConfiguration is not defined, so where is its definition?
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 25
Posts: 1872
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You seem to be using a third party lib which is intended for the AVR processors AND HAS NOT BEEN rewriten for the due. Have your question moved to the due forum!.

Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem was the #define. Switched it to int and it works fine
Logged

Pages: [1]   Go Up
Jump to: