Aus meinen Werten ergeben sich Leistungsdaten:
Code: Alles auswählen
Level | RPM 20 30 40 50 60 70 80 90 100 110 120 130
------------------------------------------------------
6 | 15 31 52 75 105 135 166 202 231 275 289
7 | 16 35 58 85 118 152 185 226 260 305 332
8 | 18 39 65 96 131 169 208 249 289 333 375
Bei Level 6 und RPM > 70 < 80 Leistung = 135
Bei Level 7 und RPM > 60 < 70 Leistung = 118
usw.
Ich denke das geht auch einfacher, so das ich nicht alle Werte einzeln bestimmen muss.
Ich hab ja schon als Ausgabe Level und RPM
Nun muss ich ja Anhand der vorhanden Daten die Leistung angezeigt bekommen.
Was benutze ich dafür?
Ich denke ein Array ist dafür gut geeignet?
Beispiel:
Code: Alles auswählen
[
{
"Level": 6,
"20": 15,
"30": 31,
"40": 52,
"50": 69,
"60": 89,
"70": 106,
"80": 125,
"90": 143
},
{
"Level": 7,
"20": 16,
"30": 35,
"40": 52,
"50": 70,
"60": 88,
"70": 107,
"80": 124,
"90": 142
},
{
"Level": 8,
"20": 18,
"30": 39,
"40": 65,
"50": 87,
"60": 111,
"70": 135,
"80": 158,
"90": 180
}
]
Sollte das Array in eine Extra Datei, damit es übersichtlich bleibt?
Ich könnte das ja mit:
Code: Alles auswählen
import powerarray.py
Wie rufe ich jetzt aber die Daten passend zu Level und RPM ab?
Bis jetzt habe ich:
Code: Alles auswählen
import time
import pigpio
import readRPM
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
count = 5
RPM_GPIO = 4
RUN_TIME = 9600.0
SAMPLE_TIME = 2.0
pi = pigpio.pi()
p = readRPM.reader(pi, RPM_GPIO)
start = time.time()
while (time.time() - start) < RUN_TIME:
input_state = GPIO.input(20)
if input_state == False:
if count < 24:
count = count + 1
RPM = p.RPM()
print('Level', count, 'RPM={}'.format(int(RPM+0.5)))
time.sleep(SAMPLE_TIME)
input_state = GPIO.input(21)
if input_state == False:
if count > 1:
count = count - 1
RPM = p.RPM()
print('Level', count, 'RPM={}'.format(int(RPM+0.5)))
time.sleep(SAMPLE_TIME)
RPM = p.RPM()
time.sleep(SAMPLE_TIME)
print("RPM={}".format(int(RPM+0.5)))