I need help with a project.

So here's what I'm trying to do. I have programmed a series of 4 LED's to repeatedly turn on then off one after the other. I have another set of 4 LED's and what I'm attempting to do is create a program that when I press a button, depending on which light from the first set is on, one of the lights from the second set while turn on. Now, I've gotten as close as I could go with what I know, but I hit a problem that I hope is the only thing keeping me from finishing it. I had set up the sequence for the first LED set in "void_loop" with a "delay" between eachother. But it seem that with the "delay" function, I can't do anything while it's running. Now, I've heard from someone that the function "millis" makes a good replacement for "delay", but for the life of me, I can't figure out how to use this function. So can anyone help me out?

In the IDE there is an example called "blink without delay". Go to File, Examples, Digital. The example uses millis() to control timing without "blocking" or stopping the program.

If you're pressing buttons then you could change the button presses to trigger an interrupt and put the code in the interrupt while the main loop stays as it is.

Interrupts have priority and should execute while the main loop is paused.

You could try to do it with millis() but you'll probably find that the interrupt way is more elegant.

raschemmel: Post your code if you want to talk about it. If you are not going to post it, don't talk about it.

Sorry about that. Here.

int entrada_1 = 0;

void setup() {

pinMode (P1_0,OUTPUT); pinMode (P1_1,OUTPUT); pinMode (P1_2,OUTPUT); pinMode (P1_3,OUTPUT); pinMode (P1_5,OUTPUT); pinMode (P2_0,OUTPUT); pinMode (P2_1,OUTPUT); pinMode (P2_2,OUTPUT); pinMode (P1_7, INPUT_PULLUP);

digitalWrite (P1_0, LOW); digitalWrite (P1_1, LOW); digitalWrite (P1_2, LOW); digitalWrite (P1_3, LOW); digitalWrite (P1_5, LOW); digitalWrite (P2_0, LOW); digitalWrite (P2_1, LOW); digitalWrite (P2_2, LOW);

}

void loop() { digitalWrite (P1_0, HIGH); delay(1000); digitalWrite (P1_0, LOW); digitalWrite (P1_1, HIGH); delay(1000); digitalWrite (P1_1, LOW); digitalWrite (P1_2, HIGH); delay(1000); digitalWrite (P1_2, LOW); digitalWrite (P1_3, HIGH); delay(1000); digitalWrite (P1_3, LOW);

}

I wrote a demo sketch in the first post in this Thread that illustrates using the Blink Without Delay technique to blink a few LEDs.

…R

Rather than asking you for code and then criticising your forum posting technique when you provide it I will instead say that the code below does what you want on an Arduino.

On an Arduino you will need to install the PinChangeInt library http://playground.arduino.cc/Main/PinChangeInt

How it works on your msp430 will be a mystery though.

#include <PinChangeInt.h>

void setup()
{

  pinMode (8,OUTPUT);
  pinMode (9,OUTPUT);
  pinMode (10,OUTPUT);
  pinMode (11,OUTPUT);
  pinMode (12,OUTPUT);
  pinMode (13,OUTPUT);
  pinMode (6, INPUT);
   
  PCintPort::attachInterrupt(6, &interuptfunction, FALLING); 
   
  digitalWrite (8,LOW);
  digitalWrite (9,LOW);
  digitalWrite (10,LOW);
  digitalWrite (11,LOW);
  digitalWrite (12,LOW);
  digitalWrite (13,LOW);
  digitalWrite (6, HIGH);

}

void interuptfunction() {
  digitalWrite (11, digitalRead(8));
  digitalWrite (12, digitalRead(9));
  digitalWrite (13, digitalRead(10));
};

void loop()
{
     digitalWrite (8, HIGH);
     delay(1000);
     digitalWrite (8, LOW);
     digitalWrite (9, HIGH);
     delay(1000);
     digitalWrite (9, LOW);
     digitalWrite (10, HIGH);
     delay(1000);
     digitalWrite (10, LOW);
}

m12lrpv: How it works on your msp430 will be a mystery though.

Ah! I wasted nearly an hour trying to figure out what all that bizarre pin stuff was. :astonished:

http://www.ti.com/lsds/ti/microcontroller/16-bit_msp430/overview.page?HQS=msp430

Yes, well, had I actually used my MSP430 with its ugly IDE, I probably would have twigged to it too. That was way back before my operation ...