The interesting part of this little and silly project is the use of an analog input to check the status of two pushbuttons.
The schematic is included in the source code you can add a 9v bat. with a 7805 regulator and an on-off switch.
Enjoy.
Errata: Ops!, there is a 1k pullup resistor missing in the schematic, so please add this to the pin 4...
'**************************************************************** '* Name : MaraTron+12F675 * '* Author : Ivan Rosales, Guadalajara México * '* Notice : Copyright (c) 2011 Ivan Rosales * '* : All Rights Reserved * '* Date : 27/08/2011 * '* Version : 1.0 * '* Notes : Quiz Game (Two Players + Audience) * '* : * '* '* '* Vdd '* + '* | '* | '* .-. '* | | PIC12F675 '* | |1K ___ Red '* '-' -o|° |o- LED Green '* | .--------o| |o---->|-. LED Blue '* .----o----o-------)--------o| |o-------)--->|-. LED '* | | | .-o|___|o-------)------)--->|-. '* | o | o | | | | | '* |=|> |=|> | | | | | '* | o | o Red | Blue| | | | '* Correct |Incorrect| | | | | | '* | | | o | o | | | '* | | |=|> |=|> | | | '* | | | o | o | | | '* | .-. | | | | | '* | | | | | | | | '* | | |1K | | | | | '* | '-' | | | | | '* | | | | | | | '* | | | | | | | '* '----o----o-------o------o---------------o------o------' '* | '* === '* GND '**************************************************************** @ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF ansel=%00111000 'Use GP4/AN3 (Pin 3) as analog input adcon0 = %00001101 cmcon=7 'Don't use analog comparator trisio=%111000 ' option_reg=0 'Enable Pull-Ups wpu=$FF 'Config Pull-Ups (GP3 DOESN'T have Pull-Up) DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 'Definitions Rojo VAR GPIO.0 Verde var GPIO.1 Azul var GPIO.2 Bot1 var GPIO.3 Bot2 var GPIO.5 Todos var bit Cont var byte Tiempo var byte SiNo var word gpio=0 'Turn off LEDs todos=0 Pral: gosub do_adc 'Get ADC reading if !bot1 and !rojo and !Azul then 'If "Red" player is the fastest high Rojo gosub do_shuffle endif if !bot2 and !Rojo and !azul then 'If "Blue" player is the fastest high Azul gosub do_shuffle endif if sino=0 then 'If the "Answer" is correct gpio=0 todos=0 endif if sino=1 and !todos and (rojo or azul)then 'If the "Answer" is incorrect (First player fails) toggle azul toggle rojo repeat gosub do_adc until sino=3 todos=1 endif if sino=1 and todos and (rojo or azul)then 'If the "Answer" is incorrect (Both players fails) low azul low rojo high verde 'Turn On Green (It's the audience turn's) repeat gosub do_adc until sino=3 todos=0 endif if sino=1 and verde then 'If the "Answer" is incorrect (Both players and audience fails) gpio=0 repeat gosub do_adc until sino=3 todos=0 endif goto pral Do_ADC: PAUSEUS 50 ' Wait for A/D channel acquisition time ADCON0.1 = 1 ' Start conversion WHILE ADCON0.1 ' Wait for it to complete WEND sino = ADRESH>>6 return Do_Shuffle: 'Just a little dramatic effect ;) tiempo=50 for cont = 1 to 32 toggle rojo toggle azul pause tiempo tiempo=tiempo+5 next cont return end
I2CWRITE "Label" option - what does it do?
I'm working on a piece of code I found in another thread about a DS3231 RTC.
flotulopex Today, 14:04Unfortunately, the used I2CWRITE command has an optional label to jump to.
I don't get what the label is there for....