|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""A EuroPi re-imagining of the Kompari module |
| 3 | +
|
| 4 | +Input A is provided in AIN. K1 and K2 provide the lower and upper bounds |
| 5 | +
|
| 6 | +Outputs: |
| 7 | +- CV1: +5V if K1 < AIN, otherwise 0 |
| 8 | +- CV2: +5V if AIN < K2, otherwise 0 |
| 9 | +- CV3: +5V if K1 < AIN < K2, otherwise 0 |
| 10 | +- CV4: max( K1, AIN ) |
| 11 | +- CV5: min( AIN, K2 ) |
| 12 | +- CV6: max( K1, min( AIN, K2 ) ) ) |
| 13 | +
|
| 14 | +B1, B2, and DIN are not used |
| 15 | +
|
| 16 | +@author Chris Iverach-Brereton |
| 17 | +@year 2023 |
| 18 | +""" |
| 19 | + |
| 20 | +from europi import * |
| 21 | +from europi_script import EuroPiScript |
| 22 | + |
| 23 | +class Kompari(EuroPiScript): |
| 24 | + """The main Kompari script. See module comment for usage |
| 25 | + """ |
| 26 | + HIGH_VOLTAGE = 5.0 |
| 27 | + LOW_VOLTAGE = 0.0 |
| 28 | + |
| 29 | + def __init__(self): |
| 30 | + super().__init__() |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def display_name(cls): |
| 34 | + return "Kompari" |
| 35 | + |
| 36 | + def main(self): |
| 37 | + """Run the main loop |
| 38 | + """ |
| 39 | + while True: |
| 40 | + lower_bound = k1.percent() |
| 41 | + upper_bound = k2.percent() |
| 42 | + x = ain.percent() |
| 43 | + |
| 44 | + if lower_bound < x: |
| 45 | + cv1.voltage(self.HIGH_VOLTAGE) |
| 46 | + else: |
| 47 | + cv1.voltage(self.LOW_VOLTAGE) |
| 48 | + |
| 49 | + if x < upper_bound: |
| 50 | + cv2.voltage(self.HIGH_VOLTAGE) |
| 51 | + else: |
| 52 | + cv2.voltage(self.LOW_VOLTAGE) |
| 53 | + |
| 54 | + if lower_bound < x and x < upper_bound: |
| 55 | + cv3.voltage(self.HIGH_VOLTAGE) |
| 56 | + else: |
| 57 | + cv3.voltage(self.LOW_VOLTAGE) |
| 58 | + |
| 59 | + cv4.voltage(max(lower_bound, x) * MAX_OUTPUT_VOLTAGE) |
| 60 | + cv5.voltage(min(x, upper_bound) * MAX_OUTPUT_VOLTAGE) |
| 61 | + cv6.voltage(max(lower_bound, min(x, upper_bound)) * MAX_OUTPUT_VOLTAGE) |
| 62 | + |
| 63 | + oled.fill(0) |
| 64 | + oled.centre_text(f"{lower_bound:0.1f} {x:0.1f} {upper_bound:0.1f}") |
| 65 | + oled.show() |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + Kompari().main() |
0 commit comments