Go Down

Topic: Error while trying to use scheduler.startLoop in scheduler library ardiuno DUE (Read 1 time) previous topic - next topic

alibaba9292

Hi there guys!

I am new to using the ardiuno due. (just got it in today) I am actually having a bit of trouble trying to compile the code. I changed the Wprogram.h to Arduino.h and the example sketch compiles fine. The problem starts when I try to compile the sketch using Scheduler.startLoop.
The error that pops up is: expected unqualified-id before '.' token. and it highlights Scheduler.startLoop
{I am trying to run two loops simultaneously where one displays the pressure sensor value from a load cell and the other displays a desired value (input from the serial monitor). }
I would really appreciate it if some one could help me out with what is it exactly that I am doing wrong! The code is as follows.

#include <Scheduler.h>
//variables for actual_value
const int digitPins1[4] = {
 4, 5, 6
};                     //4 common anode pins of the actual_value
const int clockPin1 = 11;    //74HC595 Pin 11
const int latchPin1 = 12;    //74HC595 Pin 12
const int dataPin1 = 13;     //74HC595 Pin 14
const int pressurePin = A0;  //pressure sensor pin
const byte digit1[10] =      //actual seven segment digits in bits
{
 B00111111, //0
 B00000110, //1
 B01011011, //2
 B01001111, //3
 B01100110, //4
 B01101101, //5
 B01111101, //6
 B00000111, //7
 B01111111, //8
 B01101111  //9
};
int digitBuffer1[3] = {
 0
};
int digitScan1 = 0;
float pressureValue;

//variables for desired_display

const int digitPins2[3] = {
 A1, A2, A3
};                 //4 common anode pins of the desired_display
const int clockPin2 = 11;    //74HC595-2 Pin 11
const int latchPin2 = 12;    //74HC595-2 Pin 12
const int dataPin2 = 13;     //74HC595-2 Pin 14
const byte digit2[10] =      //desired seven segment digits in bits
{
 B00111111, //0
 B00000110, //1
 B01011011, //2
 B01001111, //3
 B01100110, //4
 B01101101, //5
 B01111101, //6
 B00000111, //7
 B01111111, //8
 B01101111  //9
};
int digitBuffer2[3] = {
 0
};
int digitScan2 = 0;
unsigned int desiredValue = 0; //desiredValue input from the computer using se
char incomingByte;

void setup() {
 Scheduler.startLoop(loop1);
 //setup for actual_display
 for (int i = 0; i < 3; i++)
 {
   pinMode(digitPins1, OUTPUT);
 }
 pinMode(pressurePin, INPUT);
 pinMode(latchPin1, OUTPUT);
 pinMode(clockPin1, OUTPUT);
 pinMode(dataPin1, OUTPUT);

 //setup for desired_display
 for (int i = 0; i < 3; i++)
 {
   pinMode(digitPins2, OUTPUT);
 }
 pinMode(latchPin2, OUTPUT);
 pinMode(clockPin2, OUTPUT);
 pinMode(dataPin2, OUTPUT);
}

//writes the actual_pressure value on display
void updateDispActual() {
 for (byte j = 0; j < 3; j++)
   digitalWrite(digitPins1[j], LOW);

 digitalWrite(latchPin1, LOW);
 shiftOut(dataPin1, clockPin1, MSBFIRST, B11111111);
 digitalWrite(latchPin1, HIGH);

 delayMicroseconds(100);
 digitalWrite(digitPins1[digitScan1], HIGH);

 digitalWrite(latchPin1, LOW);

 shiftOut(dataPin1, clockPin1, MSBFIRST, ~digit1[digitBuffer1[digitScan1]]);

 digitalWrite(latchPin1, HIGH);
 digitScan1++;
 if (digitScan1 > 2) digitScan1 = 0;
}
//wrties desired_pressure value to display
void updateDispDesired() {
 for (byte j = 0; j < 3; j++)
   digitalWrite(digitPins2[j], LOW);

 digitalWrite(latchPin2, LOW);
 shiftOut(dataPin2, clockPin2, MSBFIRST, B11111111);
 digitalWrite(latchPin2, HIGH);

 delayMicroseconds(100);
 digitalWrite(digitPins2[digitScan2], HIGH);

 digitalWrite(latchPin2, LOW);

 shiftOut(dataPin2, clockPin2, MSBFIRST, ~digit2[digitBuffer2[digitScan2]]);

 digitalWrite(latchPin2, HIGH);
 digitScan2++;
 if (digitScan2 > 2) digitScan2 = 0;
}

void loop() {
 //converts digital value read by adc to kg
 pressureValue = (((analogRead(pressurePin) / 1023.0) * 5.0) / 0.0099);
 //pressure value display
 pressureValue = int(pressureValue);
 digitBuffer1[2] = int(pressureValue) / 1000;
 digitBuffer1[1] = (int(pressureValue) % 100) / 10;
 digitBuffer1[0] = (int(pressureValue) % 10);
 updateDispActual();
 delay(2);
}

void loop1() {
 if (Serial.available() > 0) {   // something came across serial
   desiredValue = 0;         // throw away previous integerValue
   while (1) {           // force into a loop until 'n' is received
     incomingByte = Serial.read();
     if (incomingByte == '\n') break;   // exit the while(1), we're done receiving
     if (incomingByte == -1) continue;  // if no characters are in the buffer read() returns -1
     desiredValue *= 10;  // shift left 1 decimal place
     // convert ASCII to integer, add, and shift left 1 decimal place
     desiredValue = int(((incomingByte - 48) + desiredValue));
     if (desiredValue > 420)
       desiredValue = 420;

     Serial.println(desiredValue);
   }
 }

 digitBuffer2[2] = int(desiredValue) / 100;
 digitBuffer2[1] = (int(desiredValue) % 100) / 10;
 digitBuffer2[0] = (int(desiredValue) % 10);
 updateDispDesired();
 delay(2);

 yield();
}

Palliser

Hello alibaba9292,

Wprogram.h? I am not sure but it seems to me that you are using the Arduino Schedule library for AVR.
http://playground.arduino.cc/Code/Scheduler

This library is not intended for Arduino DUE (SAM based).

The IDE 1.5.x has its own scheduler library. Why not try the MultipleBlinks example as a start point?.
File->Examples->Scheduler

Regards, Palliser

alibaba9292

@Palliser
THANK YOU!!!!!!!!!!!!!!!!!!!!!!! I am so stupid that is exactly what I was doing :D
cant thank you enough for your help :D
I think now should be able to ace my final year project! everything was working well individually. What I couldnt find was was a way to concurrently do all my 3 functions; display desired pressure value, display current pressure value and the third being a control loop to to reach desired value.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy