Go Down

Topic: Small programming problem. Might be me. (Read 8460 times) previous topic - next topic

Soapy29

Quote
He also said to come back in two weeks.

7+ weeks.

AWOL

#31
Jan 08, 2011, 09:58 pm Last Edit: Jan 08, 2011, 09:59 pm by AWOL Reason: 1
Quote
7+ weeks.
No, that was PaulS, not Rob, when he was telling you about millis rollover.
Are you even listening?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Soapy29

Eh, kinda. I listen when he said 7+ weeks. Not who said it at what time.

AWOL

Without sounding weird, can I ask how old you are?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Soapy29

Sure. I'm 12 turning 13 in a month or less.

AWOL

OK, I think we can cut you some slack then.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Soapy29

#36
Jan 08, 2011, 10:04 pm Last Edit: Jan 08, 2011, 10:06 pm by Soapy29 Reason: 1
Yeah. How old did you think I was? Just wondering.

AWOL

#37
Jan 08, 2011, 10:07 pm Last Edit: Jan 08, 2011, 10:07 pm by AWOL Reason: 1
Well, your spelling, capitalisation and punctuation suggested you were older, but lazy.
I detest laziness.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Soapy29

#38
Jan 08, 2011, 10:08 pm Last Edit: Jan 08, 2011, 10:12 pm by Soapy29 Reason: 1
I'm kinda older in a lot of ways. Me programming in 3+ different languages, being in robotics, (vex robotics), having an Arduino, etc. But yeah I can be kinda lazy sometimes. I'm also a good designer. And some of the grammer might come from my iPod cause I sometimes use that to upload sometimes. lol

AWOL

#39
Jan 08, 2011, 10:18 pm Last Edit: Jan 08, 2011, 10:19 pm by AWOL Reason: 1
OK, so here goes with the blink without delay explanation - a bit like one of Einstein's thought experiments.

Imagine you've been given a digital clock, a pencil and some paper.

There's a lightswitch in front of you.

Someone tells you to switch the light on in five minutes time.

(at least) Two ways of doing this:
1) Look at the clock, note the time now, add five minutes to that time, and just keep staring at the clock until that time is reached. This is what "delay" does. Because you're staring at the clock, you can't do anything else, like answer the phone or watch Barney on TV.

2) Look at the clock, note the time now, add five minutes to that time.
Watch TV for a couple of seconds, look at the clock. Is the time now greater than the time you wrote down? No, so watch the TV for a bit longer.
Look at the clock.
Is the time now greater than the time you wrote down?
And so on.
Want to switch the radio on after three minutes?
So, write that time down and each time you look down, compare two times.

See?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Soapy29

Ahhhhh. That makes a lot more sence now! The second one you can do 2 things. Now I just have to figure out how. I know you use millis() and previoustime and currenttime something like that.

Soapy29

Cwap. It still only does one thing! Here's my code that I edited from the blink without delay:
Code: [Select]

int potPin= 5;
int potVal= 0;
int delay1= 50;
int delay2= 60;
int pinArray[]= {5, 6, 7, 8, 9, 10, 11, 12};
int count= 0;
long previousMillis1 = 0;        // will store last time LED was updated
long previousMillis2 = 0;        // will store last time LED was updated
long interval = 0;           // interval at which to blink (milliseconds)

void setup() {
       //----------------------------------------
     //  Sets up the leds to work.
     //----------------------------------------
       for (count=0;count<8;count++) {
         pinMode(pinArray[count], OUTPUT);
         digitalWrite(pinArray[count], HIGH);
       }
}

void loop()
{
 // here is where you'd put code that needs to be running all the time.

 // check to see if it's time to blink the LED; that is, if the
 // difference between the current time and last time you blinked
 // the LED is bigger than the interval at which you want to
 // blink the LED.
 unsigned long currentMillis = millis();

 if(currentMillis - previousMillis1 > interval) {
   // save the last time you blinked the LED
   previousMillis1 = currentMillis;  

   // if the LED is off turn it on and vice-versa:
   if (1 == 1){
       delay1= analogRead(potPin);
     rR();
     rR();
     rR();
     rL();
     rL();
     rL();
     bR();
     bR();
     bR();
     bL();
     bL();
     bL();
       rR();
     rR();
     rR();
     rL();
     rL();
     rL();
     bR();
     bR();
     bR();
     bL();
     bL();
     bL();
     blink1();
     blink2();
       blink3();
       blink4();
       blink1();
       blink2();
       blink3();
       blink4();
       blink1();
       blink2();
       blink3();
       blink4();
 }
   if(currentMillis - previousMillis2 > interval) {
   // save the last time you blinked the LED
   previousMillis2 = currentMillis;  

   // if the LED is off turn it on and vice-versa:
   if (1 == 1){
       scroll();
 }}

}
}

void rR() {
     //-------------------------------------
     //  Blinks the right led red.
     //-------------------------------------
     delay1= analogRead(potPin);
     digitalWrite(12, LOW);
     delay(delay1);
     digitalWrite(12, HIGH);
     delay(delay1);
}

void rL() {
     //-----------------------------------
     //  Blinks the left led red.
     //-----------------------------------
     delay1= analogRead(potPin);
     digitalWrite(11, LOW);
     delay(delay1);
     digitalWrite(11, HIGH);
     delay(delay1);
}

void bR() {
     //--------------------------------------
     //  Blinks the right led blue.
     //--------------------------------------
     delay1= analogRead(potPin);
     digitalWrite(10, LOW);
     delay(delay1);
     digitalWrite(10, HIGH);
     delay(delay1);
}

void bL() {
     //------------------------------------
     //  Blinks the left led blue.
     //------------------------------------
     delay1= analogRead(potPin);
     digitalWrite(9, LOW);
     delay(delay1);
     digitalWrite(9, HIGH);
     delay(delay1);
}
//------------------------------------------------
//  Blinks the led's different colors.
//------------------------------------------------
void blink1() {
       //rR
     delay1= analogRead(potPin);
     digitalWrite(12, LOW);
     delay(delay1);
     digitalWrite(12, HIGH);
}
void blink2() {
       //rL
       delay1= analogRead(potPin);
     digitalWrite(11, LOW);
     delay(delay1);
     digitalWrite(11, HIGH);
}
void blink3() {
       //bR
       delay1= analogRead(potPin);
     digitalWrite(10, LOW);
     delay(delay1);
     digitalWrite(10, HIGH);
}
void blink4() {
       //bL
       delay1= analogRead(potPin);
     digitalWrite(9, LOW);
     delay(delay1);
       digitalWrite(9, HIGH);
}

void scroll() {
 digitalWrite(8, LOW);
 digitalWrite(7, HIGH);
 delay(delay2);
 digitalWrite(7, LOW);
 digitalWrite(6, HIGH);
 delay(delay2);
 digitalWrite(6, LOW);
 digitalWrite(5, HIGH);
 delay(delay2);
 digitalWrite(5, LOW);
 digitalWrite(6, HIGH);
 delay(delay2);
 digitalWrite(6, LOW);
 digitalWrite(7, HIGH);
 delay(delay2);
 digitalWrite(7, LOW);
 digitalWrite(8, HIGH);
 delay(delay2);
}


Did I do something wrong?

AWOL

#42
Jan 08, 2011, 10:39 pm Last Edit: Jan 08, 2011, 10:41 pm by AWOL Reason: 1
Quote
Did I do something wrong?
Well, you left all those calls to "delay" in your code.
You didn't simplify and factor your code.
You didn't put in any loops.

Why don't you slow down, start from basics, learn some stuff, simplify what you want to do and try and understand what people are trying to tell you?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Soapy29

Whoops... ::) I cut and pasted from the old code. That's why... So now I'm really confused.

Go Up