-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_pot.py
More file actions
68 lines (60 loc) · 1.89 KB
/
read_pot.py
File metadata and controls
68 lines (60 loc) · 1.89 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import serial
from sys import stdout
import time
import threading
import raspi_neopixel_lib
import Adafruit_CharLCD as LCD
# Raspberry Pi pin configuration:
lcd_rs = 26
lcd_en = 19
lcd_d4 = 13
lcd_d5 = 6
lcd_d6 = 5
lcd_d7 = 11
lcd_backlight = 9
#Neopixel Config
LED_COUNT_1 = 24
LED_PIN_1 = 18
LED_FREQ_HZ_1 = 800000
LED_DMA_1 = 5
LED_BRIGHTNESS_1 = 255
LED_INVERT_1 = False
# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2
timer = 0
# Initialize the LCD using the pins above.
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
lcd_columns, lcd_rows, lcd_backlight)
# Print a two line message
lcd.set_backlight(0)
lcd.message('Starting')
ser = serial.Serial('/dev/ttyACM0',9600)
s = []
CORSICA = raspi_neopixel_lib.Adafruit_NeoPixel(LED_COUNT_1, LED_PIN_1, LED_FREQ_HZ_1,
LED_DMA_1, LED_INVERT_1, LED_BRIGHTNESS_1)
CORSICA.begin()
while True:
read_serial=ser.readline()
stripped = read_serial.rstrip()
s.append(stripped)
if len(s) >= 20:
s.pop(0)
for val in s:
if not val.isdigit():
s.remove(val)
v = list(map(int, s))
average = int(sum(v)/len(v))
image = ((58.0/1023.0)*float(average))
rounded = "%.0f" %image
print (rounded)
kilovolts = ((10.0/1023.0)*float(average)) #(19.0/3410.0)*x+4.3 for 4.3-10.0
if timer == 50:
timer = 0
lcd.clear()
lcd.message('Voltage\n%.1f KV' %kilovolts)
elif timer % 7 == 0:
CORSICA.neopixel_percentage(float(rounded)/58)
stdout.flush()
timer += 1