Hi, i have a big Problem with a Skatch. I use a freeduino and a sparkfun lcd shild.
The skatch worked well befor i included "Serial.print("a");". If the Skatch comes to a line with Serialprint (any wher it is) the arduino restarts.
I have no idea where the problem is, i search now some days but nothing worked.
Would be grat if somone could help me.
Thank you so much.
#include "LCD_driver.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "WProgram.h"
#include "HardwareSerial.h"
int value_up;
int value_down;
int value_back;
int value_enter;
int value_analog5;
int value_analog6;
int line0=1;
int line1=1;
int ebene=0;
int contrast = 35;
int contrastbalken =0;
int aktuell=0;
int bewegen=1;
int automatik =0;
int fahren =0;
int licht =0;
int up =0;
int down =1;
int back =2;
int enter =3;
int analog5 =4;
int analog6 =5;
int IO_up =0;
int IO_down =0;
int IO_back =0;
int IO_enter =0;
int IO_analog5 =0;
int IO_analog6 =0;
int changed_up =0;
int changed_down =0;
int changed_back =0;
int changed_enter =0;
int changed_analog5 =0;
int changed_analog6 =0;
int old_up;
int old_down;
int old_back;
int old_enter;
int old_analog5;
int old_analog6;
//************************************************************************
// Main Code
//************************************************************************
void setup()
{
Serial.begin(9600);
ioinit(); //Initialize I/O
LCDInit(); //Initialize the LCD
LCDContrast(contrast);
LCDClear(BLACK); // Clear LCD to a solid color
LCDPutStr(" MCC Hohenlohe", 0, 4, YELLOW, BLACK); // Write instructions on display
LCDPutStr(" RC-Remote", 20, 4, BLUE, BLACK);
LCDPutStr(" Designed and ", 40, 4, BLUE, BLACK);
LCDPutStr(" Scripted", 56, 4, BLUE, BLACK);
LCDPutStr("by Dixi & Roman", 72, 10, BLUE, BLACK);
LCDPutStr(" Mcc-", 94, 4, YELLOW, BLACK);
LCDPutStr(" Hohenlohe.de", 110, 4, YELLOW, BLACK);
contrastbalken = contrast;
delay (3000);
LCDClear(BLUE);
}
void menu()
{
if(ebene == 0)
{
LCDPutStr(" MCC Hohenlohe", 0, 4, YELLOW, BLUE);
//LCDPutStr("Automatik", 16, 4, WHITE, BLUE);
if(line0 == 1)
{
LCDPutStr("Automatik", 32, 4, ORANGE, BLUE);
}
else
{
LCDPutStr("Automatik", 32, 4, WHITE, BLUE);
}
if (automatik == 0)
{
LCDPutStr("Aus", 32, 85, WHITE, BLUE);
}
if (automatik == 1)
{
LCDPutStr("Ein", 32, 85, GREEN, BLUE);
}
if(line0 == 2)
{
LCDPutStr("Bewegen", 48, 4, ORANGE, BLUE);
}
else
{
LCDPutStr("Bewegen", 48, 4, WHITE, BLUE);
}
if (bewegen == 1)
{
LCDPutStr("Slow ", 48, 85, GREEN, BLUE);
}
if (bewegen == 2)
{
LCDPutStr("Medium", 48, 85, YELLOW, BLUE);
}
if (bewegen == 3)
{
LCDPutStr("High ", 48, 85, RED, BLUE);
}
if(line0 == 3)
{
LCDPutStr("Fahren", 64, 4, ORANGE, BLUE);
}
else
{
LCDPutStr("Fahren", 64, 4, WHITE, BLUE);
}
if (fahren == 0)
{
LCDPutStr("Aus", 64, 85, WHITE, BLUE);
}
if (fahren == 1)
{
LCDPutStr("Ein", 64, 85, GREEN, BLUE);
}
if(line0 == 4)
{
LCDPutStr("Licht", 80, 4, ORANGE, BLUE);
}
else
{
LCDPutStr("Licht", 80, 4, WHITE, BLUE);
}
if (licht == 0)
{
LCDPutStr("Aus", 80, 85, WHITE, BLUE);
}
if (licht == 1)
{
LCDPutStr("Ein", 80, 85, GREEN, BLUE);
}
if(line0 == 5)
{
LCDPutStr("Einstellungen >", 96, 4, ORANGE, BLUE);
}
else
{
LCDPutStr("Einstellungen >", 96, 4, WHITE, BLUE);
}
if(line0 == 6)
{
LCDPutStr("Display >", 110, 4, ORANGE, BLUE);
}
else
{
LCDPutStr("Display >", 110, 4, WHITE, BLUE);
}
}
if (ebene ==1)
{
}
if(ebene ==2)
{
LCDPutStr(" Contrast", 0, 4, YELLOW, BLUE);
LCDPutStr("+", 28, 6, WHITE, BLUE);
LCDPutStr("-", 104, 6, WHITE, BLUE);
// LCDSetRect(32, 4, 118, 16, 1, WHITE);
LCDSetRect(32, 20, 75, 70, 0, WHITE);
LCDSetRect(32, 71, 75, 120, 1, RED);
LCDSetRect(76, 20, 118, 70, 1, GREEN);
LCDSetRect(76, 70, 118, 120, 1, YELLOW);
contrastbalken = 108 - contrast;
LCDSetRect(45, 4, 108, 16, 1, WHITE);
LCDSetRect(45, 4, contrastbalken, 16, 1, GREEN);
}
aktuell =1;
}
void analog()
{
value_up = analogRead(up);
value_down = analogRead(down);
value_back = analogRead(back);
value_enter = analogRead(enter);
value_analog5 = analogRead(analog5);
value_analog6 = analogRead(analog6);
if (value_up >= 500)
{
IO_up = 1;
}
else
{
IO_up = 0;
}
if (value_down >= 500)
{
IO_down = 1;
}
else
{
IO_down = 0;
}
if (value_back >= 500)
{
IO_back = 1;
}
else
{
IO_back = 0;
}
if (value_enter >= 500)
{
IO_enter = 1;
}
else
{
IO_enter = 0;
}
if (value_analog5 >= 500)
{
IO_analog5 = 1;
}
else
{
IO_analog5 = 0;
}
if (value_analog6 >= 500)
{
IO_analog6 = 1;
}
else
{
IO_analog6 = 0;
}
//delay(100);
}
void changed()
{
changed_up =0;
changed_down =0;
changed_back =0;
changed_enter =0;
changed_analog5 =0;
changed_analog6 =0;
if (old_up == 0 && IO_up == 1) // taste "up"
{
aktuell =0;
changed_up = 1;
if(ebene==0)
{
if(line0 >= 2 )
{
line0--;
}
else
if (line0 == 1)
{
line0 =6;
}
}
if(ebene==2)
{
if(contrast <=55)
{
contrast++;
LCDContrast(contrast);
contrastbalken = 108 - contrast;
LCDSetRect(45, 4, 108, 16, 1, WHITE);
LCDSetRect(45, 4, contrastbalken, 16, 1, GREEN);
}
}
}
if (old_down == 0 && IO_down == 1) // taste "down"
{
aktuell =0;
changed_down = 1;
if(ebene ==0)
{
if(line0 <= 5 )
{
line0++;
}
else
if(line0 == 6)
{
line0 = 1;
}
}
if(ebene==2)
{
if(contrast >= 1)
{
contrast--;
LCDContrast(contrast);
contrastbalken = 108 - contrast;
LCDSetRect(45, 4, 108, 16, 1, WHITE);
LCDSetRect(45, 4, contrastbalken, 16, 1, GREEN);
}
}
}
if (old_back == 0 && IO_back == 1) // taste "back"
{
aktuell=0;
changed_back = 1;
ebene = 0;
LCDClear(BLUE);
}
if (old_enter == 0 && IO_enter == 1) //taste "enter"
{
aktuell=0;
changed_enter = 1;
if( ebene == 0)
{
if (line0 == 1)
{
if (automatik == 0)
{
automatik = 1;
}
else
if (automatik ==1)
{
automatik = 0;
}
}
if (line0 ==2)
{
if (bewegen == 1)
{
bewegen++;
}
else
if (bewegen == 2)
{
bewegen++;
}
else
if (bewegen == 3)
{
bewegen=1;
}
}
if (line0 == 3)
{
if(fahren == 0)
{
fahren++;
}
else
if (fahren == 1)
{
fahren --;
}
}
if(line0 == 4)
{
if(licht == 0)
{
licht++;
}
else
if(licht == 1)
{
licht--;
}
}
if(line0 == 5)
{
ebene = 1;
}
if(line0 == 6)
{
ebene = 2;
}
}
if(ebene == 1)
{
LCDClear(BLUE);
}
if(ebene == 2)
{
LCDClear(BLUE);
}
}
old_up = IO_up;
old_down = IO_down;
old_back = IO_back;
old_enter = IO_enter;
old_analog5 = IO_analog5;
old_analog6 = IO_analog6;
// delay(100);
}
void loop()
{
analog();
changed();
if (aktuell == 0)
{
menu();
}
Serial.print("a"); [font=Verdana][color=red]//the arduino restarts if it comes to this line[/color][/font]
}