lab 2: first pic program

First, this week, I adjusted some things to my basic breadboard set-up at the suggestion of Todd. I stuck a capacitor between my power source and the 5V regulator, and I set up my test LED to get power from one side of the board and ground for the other, in order to make sure both sides were working properly. Also at Todd suggestion, I didn't put in the 22pf capacitors into the clock -- apparently, he's had more problems with than without them -- and instead stuck big capacitors between thee power and ground and the chip on both sides. I forgot what kind of capacitors they were, and since they're not labeled in any useful way, I'll have to ask.

This is the image of my set up for the first two portions of the lab. They went off smoothly, with the exception of the little hitch I had with the compiler/editor. Got the LED's blinking away, and doing a "waterfall" when I hit the switch. I didn't save the code, but it was pretty much what was given in the lab anyway.

For the "puzzle" portion of the lab, I created a math puzzle. If that weren't dorky enough on its own, I was too lazy to hook up the number of LEDs? required to display base-10 numbers, so I had numbers display in binary. Basically, the game has a series of 5 switches that would be labled with numbers (1,4,6,7,8). When a switch was flipped, the LED's would blink to display another number in binary (green is 0, yellow is 1, red means its reached the end of the number, so to not confuse people when it looped). So for instance, if when you flipped 4, it blinked yellow-yellow-yellow-red, the binary number is 111 (or 7 in base 10). All the shown numbers had the same relationship to their binary number results when their switch was pressed. The puzzle is to figure out what the relationship is.

Here's a picture (for the sake of visibility, I only have one of the switched hooked up and not labled as a number):

There are 10k resistors running from each of the switch columns to ground, so as to take away and errant energy when the switch is off and therefore floating.

And here's the code for flipped one switch (I didn't include all of them to save space -- it's all the same thing):

Define OSC 4 'clock speed 4mhz

output portd.0 'define input and output ports output portd.1 output portd.2

input portd.3 input portd.4 input portd.5 input portd.6 input portd.7

main:

if portd.3 = 1 then

    high portd.1
    pause 1000

    low portd.1
    high portd.0
    pause 1000

    low portd.0
    high portd.1
    pause 1000

    low portd.1
    pause 500
    high portd.1
    pause 1000

    low portd.1
    pause 500
    high portd.1
    pause 1000

    low portd.1
    pause 500
    high portd.1
    pause 1000

    low portd.1
    high portd.2
    pause 2000

endif

goto main

This code is very basic and doesn't account for it the user flips more than one switch. Originally, to account for that, I considered linking the conditional statements checking if a switched was flipped in a series of if-else statements. Each conditional statement would have [If (portd.3 = 1) AND (portd.4 = 0) AND . . . ] so that only one thing could be on and then the final ELSE would be if more than one was on in which case the red LED would blink. However, I looked through the PICBasic? help guide and couldn't find anything that ressembled an ifelse type of statement, so I had to rethink a little how I would check for user "error". One way I considered doing it (though I haven't tested this out yet) is to imbedded all the [if portd.3 =1 THEN] statements into an umbrella IF statement that uses OR EXCLUSIVE to check that only one switch is pressed: [IF portd.3 = 1 XOR portd.4 = 1 XOR . . . ]. This should work, assuming PICBASIC supports embedded if statements. If not, then I guess I would have to find a switch that slid to five different positions, so it could only be at one at any given moment.

body switch

So, my idea for a body switch is for a carpal tunnel danger detector (the addition of the word danger makes it sound much more exciting than it is) which would actually be a dual switch with switches that respond to pressure on both the lower palm right about the wrist where the nerve moves in and out of the hand. This would be hooked to a battery and an LED. It would all be in a flexible material in a band that wraps around the wrist like a watch or a bracelet. The material would extend and wrap up around the middle finger, with another pressure-controlled switch at the pad of the finger. The switch at the base of the palm would control whether or not any power got to the whole system, since without presure there, regardless of finger movement, no amount of typing puts you at risk for damaging the nerve. If that switch is connected, the finger pressure switch, which must require enough pressure to record a finger pressing down on a key, but not a finger simply resting on the keyboard or any surface for that matter (it's this movement in conjunction with the nerve pressure which inhibits movement that causes carpal tunnel), the LED lights up and informs you that you are in danger of hurting yourself.

I originally had problems thinking of how to register "danger" when your fingers were moving but not at rest. I first considered a flex sensor, but then realized that our fingers don't flex and unflex all that much when typing, epecially on the laptop. Then I considered recording the number of times that a finger hit the keys, so as to only light up if someone has been typing for a certain amount. I ran into problems conceptualizing the code for this, since there's no good way that I know of yet to count change, so I would have to think of that farther (I did consider, however, checking whether the switch was "on" and "off" at short time intervals and storing the results in a very large array and then comparing each result to its following one, incrementing a count when there was change. This would work, but more would have to be looking into as far as the size of the time inrements, etc.) Finally, I just assumed that you would only wear the damn thing if you were typing anyway.


Page last modified January 31, 2006, at 07:18 PM