'Hardware comes from the Arduino Leonardo PCB
'device ATmega32u4
Define CLOCK_FREQUENCY = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 4
Define LCD_EREG = PORTD
Define LCD_EBIT = 7
Define LCD_RWREG = PORTD
Define LCD_RWBIT = 0
Define ADC_SAMPLEUS = 20
Define ADC_CLOCK = 3
Define ADC_VREF = 0
'MCUCR = %00010000
ADCSRA.ADEN = 1 'Writing this bit to one enables the ADC
'ADMUX = ADC Multiplexer selection register
ADMUX.REFS1 = 0 'AVcc with external capacitor on AREF pin as it is on the Leonardo board
ADMUX.REFS0 = 1 '"
ADMUX.ADLAR = 0 'set to 1 = ADC Left Adjust Result
ADMUX.MUX4 = 0 'Analog channel selection bits in this case Port5
ADMUX.MUX3 = 0 '"
ADMUX.MUX2 = 1 '"
ADMUX.MUX1 = 0 '"
ADMUX.MUX0 = 1 '"
DDRF.5 = 0 'input ADC5, input PF5
Dim pot As Word
Lcdinit 0
WaitMs 500
pot = 0
main:
Adcin 5, pot
Lcdcmdout LcdLine1Home
Lcdout "Potentiometer"
Lcdcmdout LcdLine2Home
Lcdout #pot
WaitMs 100
Goto main
End