Академический Документы
Профессиональный Документы
Культура Документы
' '
' This shows a way to use an ordenary LED as both LED light '
' and sensor at the same time. '
' '
' You can use this to make an LED in to a "Light with touch sensor" '
' '
' This example is reworked from a site with code for ATMEL mcu. '
' http://www.thebox.myzen.co.uk/Workshop/LED_Sensing.html '
' '
' Feel free to use it if you like it. '
' If you have a better way of doing this, please let me know. '
' (You find me @ the Crownhill forum, Username: seconika '
'
' Take a look at the end of the code to get the hardware part :)
' _______________________________________________________________________'
Dim Raw1 As Byte ' get some variables to save data in.
Dim Raw2 As Byte ' get some variables to save data in.
Dim LightVal As Byte ' get some variables to save data in.
Low PORTA ' Set PORTA to logic zero.
DelayMS 100
Main:
While 1 = 1 ' Create an endless loop
'1) Turn LED on.
Low PORTA.0 ' Set PORTA.0 To logic zero.
High PORTB.7 ' Set PORTB.7 To logic one.
DelayMS 100 ' Now the Led can shine for a while :)
'2) Set LED in measurement mode (Turns the LED off)
TRISA.0 = 1 ' Set PORTA.0 To ADC input
Low PORTB.7 ' Set PORTB.7 to logic zero
'3-4) Take a measurement of the analogue voltage, this is a reference level
for later use.
Raw1 = ADIn 0 ' Read the ADC
HSerOut ["Data: ", Dec LightVal ,13] 'This serout was added for debugging...
Wend 'Make it all over again :)