Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Toggle LED with Switch (off same Adruino PIN) on: April 19, 2013, 02:17:30 am
I checked over the code yesterday and tested it for some time to see if I could find any issues or errors.

The only issue I could find was in some instances when the LED is on when I push the button it doesn't seem to switch off the LED but then can work ok for a number of times.

If anybody could provide a little feedback it would be great thank you.
2  Using Arduino / Programming Questions / Re: Toggle LED with Switch (off same Adruino PIN) on: April 18, 2013, 09:19:03 am
Below is the code which I used to create a multiplexer for Arduino - Console Shield

const int PIN9 = 9; //LED 1 and Push Button 1
const int PIN8 = 8; //LED 0 and Push Button 0

int SW1Count = 0;
int SW1State = 0;
int LSW1State = 0;

int SW0Count = 0;
int SW0State = 0;
int LSW0State = 0;

void setup () {
 pinMode(PIN9, INPUT);
 pinMode(PIN8, INPUT); 
}

void loop() {
 
  //Switch 1 and LED 1 (MSB Multiplexer)
SW1State = digitalRead(PIN9);

if (SW1State != LSW1State) {
 if (SW1State == HIGH) {
  SW1Count++;
  }
 
  LSW1State = SW1State;
 
}

if (SW1Count == 1) {
 pinMode(PIN9,OUTPUT);
digitalWrite(PIN9, HIGH);
pinMode(PIN9, INPUT);
}

if (SW1Count == 2) {
 SW1Count = 0;
}

  //Switch 0 and LED 0 (LSB Multiplexer)
SW0State = digitalRead(PIN8);

if (SW0State != LSW0State) {
 if (SW0State == HIGH) {
  SW0Count++;
  }
 
  LSW0State = SW0State;
 
}

if (SW0Count == 1) {
 pinMode(PIN8,OUTPUT);
digitalWrite(PIN8, HIGH);
pinMode(PIN8, INPUT);
}

if (SW0Count == 2) {
 SW0Count = 0;
}

}

Sorry there aren't any comments with the code just yet. I will populate with comments later this evening.

Cheers

Mike
3  Using Arduino / Programming Questions / Re: Toggle LED with Switch (off same Adruino PIN) on: March 28, 2013, 10:45:54 am
I've been told to come up with something I want to produce rather than the assignment. So I am currently putting together a flow diagram to define the specification of the code.

I am just trialing what can be achieved and what can't be achieved.
4  Using Arduino / Programming Questions / Re: Toggle LED with Switch (off same Adruino PIN) on: March 28, 2013, 09:59:36 am
That is correct.

I will attach the wiring diagram and table etc. once I get home tonight. We cannot start making the board fit to suit what we are trying to achieve.

All other functions seem straight forward to operate and I have no problem with them, but this is a problem which I need to work to continue with the project assignment (I am developing my own software flow diagram, so I am defining the project scope oppose to Teeside).

I appriciate that a pin can only be an input or an output at any single point in time. Is there a way in which it can be switched between within a void loop() rather than void setup(), not really sure what the propagation delay is like on the Adruino.

I am trying to acheive a multiplexer arrangement so that I can set the simulation up in four different modes dependant upon the output status of the LEDs.

Cheers

Mike
5  Using Arduino / Programming Questions / Toggle LED with Switch (off same Adruino PIN) on: March 28, 2013, 09:27:30 am
Hi I am Mike Harmer, I am new to the forum.

I have been given the Adruino Console - Shield from Teeside University. Currently I have no lesson notes available and I am just working out how everything goes together.

I am currently struggling to toggle an LED which is on the same Adruino PIN as the switch. I believe that it may be a debounce issue but not 100% sure. All examples look at toggling an LED which is on a different PIN to the switch which doesn't really assist me with what I am trying to achieve.

If somebody could guide me in the right direction rather than telling me the answer I would be grateful.
Pages: [1]