File: adcRead-8bit.py

package info (click to toggle)
expeyes 5.3.4%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,612 kB
  • sloc: python: 36,039; ansic: 9,754; xml: 1,010; makefile: 784; sh: 581; asm: 202; javascript: 46; php: 1
file content (26 lines) | stat: -rw-r--r-- 704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
r'''                                                                              PA0
Connect LEDs from PB0..PB7 to Ground via 5k resistors.                            |
Change the voltage at PA0 using a potentiometer, using a connection like    5V__/\/\/\__GND
'''

import time
from kuttyPy import *

ADSP2 = 2
REFS1 = 7
REFS0 = 6
ADLAR = 5
ADEN   = 7
ADIF   = 4
ADSC   = 6

setReg(DDRA,0)

def readADC(ch):        # Read the ADC channel
	setReg(ADMUX, (1 << ADLAR) |(1 << REFS1) | (1 << REFS0) | ch)         # REference source and channel number
	setReg(ADCSRA, 1 << ADEN | (1 << ADSC) | 1 << ADSP2)	# Enable, start and clock setting
	return getReg(ADCH);
	
while 1:
	print (readADC(0))
	time.sleep(1)