system
July 3, 2011, 10:42am
1
I am using the colorduino library(8x8 matirx)
I have this in the loop:
void loop()
{
setTest();
if (Serial.available() > 0)
{
unsigned char inByte = Serial.read();
// Serial.println (inByte);
// Serial.flush();
switch(inByte)
{
Serial.flush();
case 'a':
{
for( unsigned char i = 0; i < 10 ; i++)
{
setHeart();
delay(100);
setHeart2();
delay(100);
break;
}//End for
}
default:
{
for( unsigned char i = 0; i< 1 ; i++)
{
setTest();
delay(1000);
break;
}
}
//End for
}//End switch
}
// Serial.flush();
//*******************************END TEST**************************************************
/*
//****************************************BEGIN INPUT KEYBOARD**********************************
//Serial.flush();
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
switch(inByte)
{
case 'a':
//if(millis() > stateEnd)
// {
Serial.println(" \na is pressed ");
// stateStart = millis();
// stateEnd = stateStart + 1000;
//Serial.flush();
//initializeColorduino();
//setHeart();
//setSmiley();
// delay(1000);
setTest();
// setSmiley2();
//delay(1000);
//setSmiley();
break;
case 'b':
//Serial.flush();
// plasma_morph2();
// Serial.flush();
Serial.println(" \nb is pressed ");
// initializeColorduino();
setSmiley();//Showing the heart
break;
case 'c':
// Serial.flush();
Serial.println("\nc is pressed") ;
setSmiley2();
break;
case 'd':
Serial.println("\nd is pressed");
setAngry();
break;
case 'e':
Serial.println("\nd is pressed");
setSmiley2();
break;
default:
{
setAngry();
Serial.println(" \nWrong character, IDIOT!! "); // send back the value received.
break;
}
}//End switch
Serial.flush();
delay(1000);
Serial.print(inByte); // send back the value received.
}
//***************************END INPUT KEYBOARD*******************************************
*/
}//End Loop
but is doesnt do the pattern for 10 times
system
July 3, 2011, 10:45am
2
Your 'a' case falls straight into your default case - is that what you intended?
You have "Serial.flush" inside the switch but not associated with any case (that's not your problem here, but it looks odd)
system
July 3, 2011, 11:02am
3
HI awol,
thx for ur quick replay.
I want to reset the buffer, because otherwise the images overlap eatch other.
what do u mean with: that is not my probleme here?
My intention is just that u press 'a' - for now it is 1 but I have more annimations that u will see 10 times the heart annimation.
THX anyway
system
July 3, 2011, 11:05am
4
You break out of your "for" loop on the first time through - if you only want one iteration, you don't need a "for" loop.
system
July 3, 2011, 11:10am
5
I want it 10 times. I mean I have now only 'a' but normally I have 'b', 'c' etc.
But it must 10 times.
It goes now only 2 times. not 10 times.
and it has to do 10 times - like in the code
But I have some problems with the buffer.
Can u give me an example.
thx
system
July 3, 2011, 11:12am
6
See reply #3 , in particular the second word.
system
July 3, 2011, 11:17am
7
??
did u test it.
Then u can see it by urself. that it doesnt reset the buffer.
void loop()
{
setTest();
if (Serial.available() > 0)
{
unsigned char inByte = Serial.read();
// Serial.println (inByte);
// Serial.flush();
switch(inByte)
{
Serial.flush();
case 'a':
{
for( unsigned char i = 0; i < 10 ; i++)
{
setHeart();
delay(100);
setHeart2();
delay(100);
break;
}//End for
}
case 'b':
{
for(unsigned char i = 0; i < 10; i++)
{
setSmiley();
delay(500);
setSmiley2();
delay(500);
break;
}
}
default:
{
setTest();
delay(1000);
break;
}
//End for
}//End switch
}
}//End Loop
// Serial.flush();
if u test it u see it by urself that is doesnt work correct.
the images are overlapping
system
July 3, 2011, 11:24am
8
(Can you please stop typing in txt - it is really hard to read.)
I can't test it, because I don't have your hardware.
However, you do, so you tell me what this bit of code does:
for(unsigned char i = 0; i < 10; i++)
{
setSmiley();
delay(500);
setSmiley2();
delay(500);
break;
}
system
July 3, 2011, 11:32am
9
HI Awol,
sorry then.
But u have to get the hardware it is the only way to test it.
then u see it by urself.
it has to do it with the buffer.
The images are overlapping eatch other.
system
July 3, 2011, 11:34am
10
I won't be getting any hardware any time soon, but will you be looking at that "break"?
system
July 3, 2011, 2:17pm
11
The break statement has a number of uses. Using break inside a for loop or a while loop causes the loop to stop looping, regardless of the continue condition.
A break statement is also required at the end of each case statement in a switch statement, to break out of the switch statement.
Move the break statement out of the for loop. Put it after the for loop, at the end of the case section.
And, if you don't start spelling out words, and using proper capitalization and punctuation, you will not be getting more help here.
Is this line correct for what you want?
for( unsigned char i = 0; i < 10 ; i++)
Or should it be?
for( unsigned char i < 10 ; i++)
"modified my obvious error out."
AWOL:
Or should it be?
Code:
for( unsigned char i == 0 & i < 10 ; i++)
Doh! I did it again. I need to be more awake before I post impossible for loops!
Mak