« »

PComp 1: Solder Doesn’t Rhyme With Boulder

It’s been a long time since I did anything that required this much hand-eye coordination.

N2S: Measure wires along where they’ll be connecting before cutting them, add about an inch and then cut and strip.

I’m not sure what all the blue wires on the lab photo are for, I’m going to build this thing and then I’m going to try and understand it. No problems getting it working, but I still don’t have a clue how it works.

Here's my setup

Here's my setup

I’m trying to follow the charge from the 5V through the board but I get lost as soon as I get to the switch.  Where is the power for the LEDs coming from?

Ok, so I changed the code from:

void loop() {
  // read the switch input:
  switchState = digitalRead(switchPin);

  if (switchState == 1) {
    // if the switch is closed:
    digitalWrite(yellowLedPin, HIGH);
    digitalWrite(redLedPin, LOW);
  }
  else {
    // if the switch is open:
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(redLedPin, HIGH);
  }

to

void loop() {
  // read the switch input:
  switchState = digitalRead(switchPin);

  if (switchState == 1) {
    // if the switch is closed:
    digitalWrite(redLedPin, HIGH);
    digitalWrite(yellowLedPin, LOW);
  }
  else {
    // if the switch is open:
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, HIGH);
  }

and the lights flip flopped as I expected.  So switching both to HIGH or LOW simultaneously ought to make both LEDs light up or turn off.  I just did it, it does.  I think I’m getting the hang of this.

What I really want to do is to make a switch that detects the length of the press and only lights an LED if the user makes three consecutive presses of the correct lengths.  If I knew how to program, I would approach the problem as follows:

  1. Setup all the necessary variables, inputs, and outputs
  2. Tell the Arduino to listen for a switch press
  3. Measure the length of the first switch press and store it after passing it through constrain(duration,shortvalue,longvalue) to reduce it to either a predetermined “short” or “long” value
  4. Measure the length of the second switch press and store it after similarly constraining it
  5. Measure the length of the third switch press and store it after similarly constraining it
  6. Match the pattern of values, say long, short, long to a stored combination; if it matches, light up the LED, otherwise reset and start over.

I’m going to see if I can figure this out with someone’s help this afternoon.

Comments

Comments are closed.