File: adcRead-8bit.py

package info (click to toggle)
expeyes 4.8.8%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,276 kB
  • sloc: python: 33,528; ansic: 9,754; xml: 1,010; makefile: 828; javascript: 824; sh: 580; asm: 202; php: 1
file content (26 lines) | stat: -rw-r--r-- 701 bytes parent folder | download | duplicates (3)
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
'''                                                                              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)