Warning: main(processing-parser.php) [function.main]: failed to open stream: No such file or directory in /home/mandalat/public_html/itp/fall04/physical-computing/project-2.php on line 3

Warning: main(processing-parser.php) [function.main]: failed to open stream: No such file or directory in /home/mandalat/public_html/itp/fall04/physical-computing/project-2.php on line 3

Warning: main() [function.include]: Failed opening 'processing-parser.php' for inclusion (include_path='/usr/lib/php:.:/usr/php4/lib/php:/usr/local/php4/lib/php') in /home/mandalat/public_html/itp/fall04/physical-computing/project-2.php on line 3
Rich Hauck @ ITP: fall.04: Physical Computing

fall.04: Physical Computing

// Physical Computing Project 2: Alarm Clock

11/3/2004


DEFINE OSC 4 'set clock
inv9600 con 16468'set a constant with the baudmode 9600-8-n-1-inverted:
btnClicked var byte 'value set by buttons to check against color choice
randVar VAR WORD 'random number to choose color values from arrays
choiceVar var word 'formatted version of randVar
counter var byte 'counter sets which LED user is answering

start:

'r array represents values for R in RGB. Values are 0-255
r var byte(5)
r(0)=244 'red
r(1)=0 'green
r(2)=0 'blue
r(3)=254 'orange
r(4)=254 ' yellow

'g array represents values for G in RGB. Values are 0-255
g var byte(5)
g(0)=0 'red
g(1)=254 'green
g(2)=0 'blue
g(3)=150 'orange
g(4)=0 ' yellow

'b array represents values for B in RGB. Values are 0-255
b var byte(5)
b(0)=0 'red
b(1)=0 'green
b(2)=254 'blue
b(3)=0 'orange
b(4)=254 ' yellow

'Define Buttons
input PORTB.7'red button
input PORTB.6'green button
INPUT PORTB.5'blue button
INPUT PORTB.4'orange button
INPUT PORTB.3'yellow button

'LED #1
OUTPUT PORTC.3'red
OUTPUT PORTD.0'green
OUTPUT PORTD.1'blue

'LED #2
OUTPUT PORTC.4'red
OUTPUT PORTD.3'green
OUTPUT PORTD.2'blue

'LED #3
OUTPUT PORTD.7'red
OUTPUT PORTD.6'green
OUTPUT PORTD.5'blue

'ALARM
output PORTA.1

'initialize variables
counter=0
btnClicked=5'set higher than array length
choiceVar=5'set higher than array length

main:
HIGH PORTA.1
gosub setRandom

'**********test first light**********'
while counter<1
gosub checkBtns
'PWM Pin,Duty,Cycle for LED #1
PWM PORTC.3,r(choiceVar), 1
PWM PORTD.0,g(choiceVar), 1
PWM PORTD.1,b(choiceVar), 1
wend
pause 500
btnClicked=5'reset btnClicked in case same value comes up
'Turn off LED #1
PWM PORTC.3,0, 1
PWM PORTD.0,0, 1
PWM PORTD.1,0, 1

'**********test second light**********'
gosub setRandom
while counter<2
gosub checkBtns
'PWM Pin,Duty,Cycle for LED #2
PWM PORTC.4,r(choiceVar), 1
PWM PORTD.3,g(choiceVar), 1
PWM PORTD.2,b(choiceVar), 1
wend
pause 500
btnClicked=5'reset btnClicked in case same value comes up
'Turn off LED #2
PWM PORTC.4,0, 1
PWM PORTD.3,0, 1
PWM PORTD.2,0, 1

'**********test third light**********'
gosub setRandom
while counter<3
gosub checkBtns
'PWM Pin,Duty,Cycle for LED #3
PWM PORTD.7,r(choiceVar), 1
PWM PORTD.6,g(choiceVar), 1
PWM PORTD.5,b(choiceVar), 1
wend
'Turn off LED #3
PWM PORTD.7,0, 1
PWM PORTD.6,0, 1
PWM PORTD.5,0, 1
LOW PORTA.1'turn off alarm
goto main

setRandom:
adcin 0, randVar'generate random number
choiceVar = randvar//4'limit choiceVar to 4 values
return

checkBtns:
'Check Value sent by button
if PORTB.7 then btnClicked=0'if red button clicked
if PORTB.6 then btnClicked=1'if green button clicked
if PORTB.5 then btnClicked=2'if blue button clicked
if PORTB.4 then btnClicked=3'if orange button clicked
if PORTB.3 then btnClicked=4'if yellow button clicked
if btnClicked=choiceVar then counter=counter+1
return

top

11/1/2004

I created subroutines to clean up some of the code. My serial cord wasn't setup properly from the previous night, so I fixed that. I started outputing the btnClicked and choiceVar values to determine if they matched. Now, oddly enough, when I power the board the LED will only sometimes light. Furthermore, it will send a series of values to the serial out and then stops. Code below (changes in bold):

DEFINE OSC 4 'set clock
'set a constant with the baudmode 9600-8-n-1-inverted:
inv9600 con 16468
btnClicked var byte 'value set by buttons to check against color choice
randVar VAR WORD 'random number to choose color values from arrays
choiceVar var word 'formatted version of randVar
needRV var bit 'boolean determines whether to create random variable
counter var byte 'counter sets which LED user is answering

start:

'r array represents values for R in RGB. Values are 0-255
r var byte(5)
r(0)=255 'red
r(1)=0 'green
r(2)=0 'blue
r(3)=255 'orange
r(4)=255 ' yellow

'g array represents values for G in RGB. Values are 0-255
g var byte(5)
g(0)=0 'red
g(1)=255 'green
g(2)=0 'blue
g(3)=150 'orange
g(4)=0 ' yellow

'b array represents values for B in RGB. Values are 0-255
b var byte(5)
b(0)=0 'red
b(1)=0 'green
b(2)=255 'blue
b(3)=0 'orange
b(4)=255 ' yellow

'Define Buttons
input PORTB.7'red button
input PORTB.6'green button
INPUT PORTB.5'blue button
INPUT PORTB.4'orange button
INPUT PORTB.3'yellow button

'LED #1
OUTPUT PORTC.3'red
OUTPUT PORTD.0'green
OUTPUT PORTD.1'blue

'LED #2
OUTPUT PORTC.4'red
OUTPUT PORTD.3'green
OUTPUT PORTD.2'blue

'LED #3
OUTPUT PORTD.7'red
OUTPUT PORTD.6'green
OUTPUT PORTD.5'blue

counter=0'initialize counter
needRV=1'initialize
btnClicked=5

setRandom:
RANDOM randVar'generate random number
choiceVar = randvar/10000'divide random number to give 1-digit integer
if choiceVar>=5 then choiceVar=4
needRV=0
checkBtns:
'Check Value sent by button
if PORTB.7 then btnClicked=0'if red button clicked
if PORTB.6 then btnClicked=1'if green button clicked
if PORTB.5 then btnClicked=2'if blue button clicked
if PORTB.4 then btnClicked=3'if orange button clicked
if PORTB.3 then btnClicked=4'if yellow button clicked
if btnClicked=choiceVar then counter=counter+1
needRV=0'don't need random number during loop
debugger:
'debugging
serout2 portc.6, inv9600, ["Choice: ", dec choiceVar, 13, 10]
serout2 portc.6, inv9600, ["Button: ", dec btnClicked, 13, 10]

main:
gosub debugger
if needRV=1 then setRandom

'**********test first light**********'
while counter<1
gosub checkBtns
'PWM Pin,Duty,Cycle for LED #1
PWM PORTC.3,r(choiceVar), 1
PWM PORTD.0,g(choiceVar), 1
PWM PORTD.1,b(choiceVar), 1
wend
btnClicked=5'reset btnClicked in case same value comes up

'Turn off LED #1
PWM PORTC.3,0, 1
PWM PORTD.0,0, 1
PWM PORTD.1,0, 1
'**********test second light**********'
needRV=1'need random number, sets choiceVar
while counter<2
gosub checkBtns
'PWM Pin,Duty,Cycle for LED #2
PWM PORTC.4,r(choiceVar), 1
PWM PORTD.3,g(choiceVar), 1
PWM PORTD.2,b(choiceVar), 1
wend
btnClicked=5'reset btnClicked in case same value comes up
'Turn off LED #2
PWM PORTC.4,0, 1
PWM PORTD.3,0, 1
PWM PORTD.2,0, 1
'**********test third light**********'
needRV=1'need random number, sets choiceVar
while counter<3
gosub checkBtns
'PWM Pin,Duty,Cycle for LED #3
PWM PORTD.7,r(choiceVar), 1
PWM PORTD.6,g(choiceVar), 1
PWM PORTD.5,b(choiceVar), 1
wend
'Turn off LED #3
PWM PORTD.7,0, 1
PWM PORTD.6,0, 1
PWM PORTD.5,0, 1
goto main

top

10/31/2004

tricolors

I hooked up all of the elements together and found a nice wooden cigar box to (hopefully) contain everything.

I soldered the tricolor leds with headers and hot-glued them to assure that the wires don't cross. I then wrote the code to include both the arrays and the random function. Unfortunately, after serveral tries, I was unable to get the code to work properly. My assumption is that the random code generator is continually setting a value in the main subroutine when it should only choose a random number once per WHILE statement. I'm also setting a variable with the buttons and comparing that button to the random number, but I'm not sure that it's working.

To debug, I tried outputing certain variables to the serial port, but even that didn't work. I decided to give up after spending the day assembling it. Code below:

DEFINE OSC 4 'set clock
'set a constant with the baudmode 9600-8-n-1-inverted:
inv9600 con 16468

btnClicked var byte 'value set by buttons to check against color choice
randVar VAR WORD 'random number to choose color values from arrays
choiceVar var word 'formatted version of randVar
needRV var bit 'boolean determines whether to create random variable
counter var byte 'counter sets which LED user is answering

start:
'r array represents values for R in RGB. Values are 0-255
r var byte(5)
r(0)=255 'red
r(1)=0 'green
r(2)=0 'blue
r(3)=255 'orange
r(4)=255 ' yellow

'g array represents values for G in RGB. Values are 0-255
g var byte(5)
g(0)=0 'red
g(1)=255 'green
g(2)=0 'blue
g(3)=150 'orange
g(4)=0 ' yellow

'b array represents values for B in RGB. Values are 0-255
b var byte(5)
b(0)=0 'red
b(1)=0 'green
b(2)=255 'blue
b(3)=0 'orange
b(4)=255 ' yellow

'Define Buttons
input PORTB.7'red button
input PORTB.6'green button
INPUT PORTB.5'blue button
INPUT PORTB.4'orange button
INPUT PORTB.3'yellow button

'LED #1
OUTPUT PORTC.3'red
OUTPUT PORTD.0'green
OUTPUT PORTD.1'blue

'LED #2
OUTPUT PORTC.4'red
OUTPUT PORTD.3'green
OUTPUT PORTD.2'blue

'LED #3
OUTPUT PORTD.7'red
OUTPUT PORTD.6'green
OUTPUT PORTD.5'blue

counter=0'initialize counter
needRV=1'initialize
btnClicked=5

setRandom:
RANDOM randVar'generate random number
choiceVar = randvar/10000'divide random number to give 1-digit integer
if choiceVar>=5 then choiceVar=4

main:
'Check Value sent by button
if PORTB.7 then btnClicked=0'if red button clicked
if PORTB.6 then btnClicked=1'if green button clicked
if PORTB.5 then btnClicked=2'if blue button clicked
if PORTB.4 then btnClicked=3'if orange button clicked
if PORTB.3 then btnClicked=4'if yellow button clicked

serout2 portc.6, inv9600, [btnClicked, 13, 10]

'if needRV=1 then setRandom
choiceVar=0

'**********test first light**********'
while counter<1
needRV=0'don't need random number during loop
'PWM Pin,Duty,Cycle for LED #1
PWM PORTC.3,r(choiceVar), 1
PWM PORTD.0,g(choiceVar), 1
PWM PORTD.1,b(choiceVar), 1

if btnClicked=choiceVar then counter=counter+1
wend
'Turn off LED #1
PWM PORTC.3,0, 1
PWM PORTD.0,0, 1
PWM PORTD.1,0, 1

'**********test second light**********'
needRV=1'need random number, sets choiceVar
while counter<2
needRV=0'don't need random number during loop
'PWM Pin,Duty,Cycle for LED #2
PWM PORTC.4,r(choiceVar), 1
PWM PORTD.3,g(choiceVar), 1
PWM PORTD.2,b(choiceVar), 1

if btnClicked=choiceVar then counter=counter+1
wend
'Turn off LED #2
PWM PORTC.4,0, 1
PWM PORTD.3,0, 1
PWM PORTD.2,0, 1

'**********test third light**********'
needRV=1'need random number, sets choiceVar
while counter<3
needRV=0'don't need random number during loop
'PWM Pin,Duty,Cycle for LED #3
PWM PORTD.7,r(choiceVar), 1
PWM PORTD.6,g(choiceVar), 1
PWM PORTD.5,b(choiceVar), 1

if btnClicked=choiceVar then counter=counter+1
wend
'Turn off LED #3
PWM PORTD.7,0, 1
PWM PORTD.6,0, 1
PWM PORTD.5,0, 1

goto main

top

10/29/2004

simple LEDs

Using regular LEDs and setting HIGH and LOW rather than integrating the tricolors, random, or arrays, I was able to generate the basic functionality with the lights and buttons. Code:

start:
input PORTB.7'red button
input PORTB.6'green button
INPUT PORTB.5'blue button

HIGH PORTD.1'this port represents the alarm

counter var byte
counter=0

main:
'*****test first light*****'
while counter<1
high PORTC.4
if PORTB.7 then counter=counter+1
wend
low PORTC.4'turn off light 1
'*****test second light*****'
while counter<2
high PORTD.3
if PORTB.6 then counter=counter+1
wend
low PORTD.3'turn off light 2
'*****test third light*****'
while counter<3
high PORTD.2
if PORTB.5 then counter=counter+1
wend
low PORTD.2'turn off light 3
LOW PORTD.1 'turn off alarm
goto main

In preparation for lighting tricolor LEDs, I modified some code from Todd's stage site.

Rather than using the random values from an empty pin, I took a step backwards and decided to use the random function. After dividing it by 10,000, the random function yields a value of 0-6, which is pretty close to the 5 color (red, green, blue, orange, yellow) limit I had in mind. Code:

' serial out is on portc.6
' serial in is on portc.7
' a digital input is on portb.0
'set a constant with the baudmode 9600-8-n-1-inverted:
inv9600 con 16468
choiceVar var word'formatted version of random number
randVar VAR WORD'random number to choose color values from arrays
'pause 500 ' start program with a half-second delay
main:
RANDOM randVar'generate random number
choiceVar = randvar/10000'divide random number to give 1-digit integer
if choiceVar>=5 then choiceVar=4
  ' send it out the serial port:
  serout2 portc.6, inv9600, [Dec choiceVar, 13, 10]
goto main

top

10/27/2004

So here's an overview of how we'll attempt to accomplish this project:

  1. The clock's alarm goes off and activates power to the breadboard.
  2. The pic generates a random number and places it into a variable.
  3. We use this variable to choose R,G, and B values from 3 separate pin arrays.
  4. These arrays values are used in a PWM call to set the first tricolor LED.
  5. The user pushes a button labeled to correspond to the LED's color to continue to the second LED.
  6. Once the user answers the three colors, the alarm is switched off and the power to the board ends.

Because I've heard that the random function in PicBasic Pro is pretty bad, we've tried reading the values from a stripped wire (stripped wire works like an antenna and returns varying noise values). I've also discovered that reading the input from an empty pin has a similar effect.

top

10/25/2004

I have recently had trouble getting up early in the morning. Part of it deals with my schedule change from a 9 to 5 job to graduate night classes. I know I'm not alone in this; getting up late has happened to all of us. We've tried setting multiple alarms, moving the clock across the room, etc. (ironically, more sleep is never a consideration).

Well, rather than have a simple switch to turn off the alarm, why not have a code to enter? I conceived of an alarm clock that, once set off, would require a user to enter a 5-digit number that was displayed on an LCD once the alarm went off.

Once presented in class, a number of my classmates expressed a few concerns. "What if we can't see the numbers?" was the primary critique. As a result, My partner and I will be creating a clock that generates three random colors on tricolor LEDs. Users will then have to push the corresponding button to match the color and shut the alarm off.

top
Rich Hauck at the Interactive Telecommunications Program at New York University