Hy,
I try to program a multitasking system and fail on an early state.
I use the DUE with the MultipleBlinks Demo. All is fine.
I use the U8glib without multitaskin to control a KS108 LCD display. All is fine.
But if I include U8g and configure U8GLIB_KS0108_128 u8g(22, 23, 24, 25, 26, 27, 28, 29, 17, 14, 15, 16, 30);
to the MultipleBlinks Demo the DUE seems to do nothing. No blink, no LCD output and no serial communication.
My code:
// Include Scheduler since we want to manage multiple tasks.
#include <Scheduler.h>
#define HDMM01_I2C_Addr 0x30
#include <U8glib.h>
U8GLIB_KS0108_128 u8g(22, 23, 24, 25, 26, 27, 28, 29, 17, 14, 15, 16, 30); // 8Bit Com: D0..D7: 22..29 en=17, cs1=14, cs2=15, di=17 (,rw=30)
//KS108: 1=Vss; 2=Vdd; 3=V0; 4=D/I; 5=R/W; 6=E; 7..14=D0..D7; 15=CS1; 16=CD2
// 17=RST; 18=Vee; 19=A; 20=K
int led1 = 13;
int led2 = 12;
int led3 = 11;
void setup() {
Serial.begin(9600);
// Setup the 3 pins as OUTPUT
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
u8g.setFont(u8g_font_4x6);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
// Add "loop2" and "loop3" to scheduling.
// "loop" is always started by default.
Scheduler.startLoop(loop2);
Scheduler.startLoop(loop3);
}
// Task no.1: blink LED with 1 second delay.
void loop() {
digitalWrite(led1, HIGH);
// IMPORTANT:
// When multiple tasks are running 'delay' passes control to
// other tasks while waiting and guarantees they get executed.
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
}
// Task no.2: blink LED with 0.1 second delay.
void loop2() {
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);
}
// Task no.3: accept commands from Serial port
// '0' turns off LED
// '1' turns on LED
void loop3() {
static char c=0;
if (Serial.available()) {
c = Serial.read();
if (c=='0') {
digitalWrite(led3, LOW);
Serial.println("Led turned off!");
}
if (c=='1') {
digitalWrite(led3, HIGH);
Serial.println("Led turned on!");
}
}
u8g.firstPage();
do
{
u8g.drawStr(0,0, "LED");
}
while( u8g.nextPage() );
// IMPORTANT:
// We must call 'yield' at a regular basis to pass
// control to other tasks.
yield();
}
The same is also without the LCD output part
u8g.setFont(u8g_font_4x6);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
and
u8g.firstPage();
do
{
u8g.drawStr(0,0, "LED");
}
while( u8g.nextPage() );
Has anyone an idea what the problem is?
Thanx
lowsax