main.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. """
  2. Author: Tobias Müller
  3. Date: 30.06.2023
  4. Version: 1.0
  5. Main File to run on the pico.
  6. """
  7. ############################## Modules ##############################
  8. from libs.foo import foo
  9. import time
  10. from machine import Pin, UART, ADC
  11. import machine
  12. ############################## Global Variables ##############################
  13. baz = foo(Pin(1), Pin(20), led_Pin_timer=Pin(5))
  14. ############################## Main ##############################
  15. def main():
  16. # Pin Definitions (Assuming these are correct)
  17. output_pin = machine.Pin(26, machine.Pin.IN)
  18. lo_minus_pin = machine.Pin(27, machine.Pin.IN)
  19. lo_plus_pin = machine.Pin(8, machine.Pin.IN)
  20. # Configure ADC
  21. adc = ADC(output_pin)
  22. print("version_1")
  23. # Function to map ADC value to desired range
  24. def map_value(value, in_min, in_max, out_min, out_max):
  25. return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
  26. # Function to read and process ECG signal
  27. def read_ecg():
  28. adc_value = adc.read_u16()
  29. signal = map_value(adc_value, 0, 65535, 0, 100) # Example mapping
  30. return signal
  31. # Configure UART for 11520 baud rate
  32. # uart = UART(0, baudrate=11520, tx=Pin(0), rx=Pin(1)) # Adjust pins as needed
  33. k=0
  34. while True:
  35. printlist=[]
  36. for i in range(100):
  37. ecg_signal = read_ecg()
  38. printlist.append(ecg_signal)
  39. # Transmit the ECG signal
  40. #uart.write(str(ecg_signal) + "\n") # Send data with newline character
  41. for ecg_signal in printlist:
  42. #k=k+1
  43. #print(k)
  44. print(ecg_signal)
  45. # Optional delay between readings
  46. #time.sleep(0.00001) # Adjust delay as needed
  47. """
  48. Main program
  49. ########################## Local Variables ############################
  50. led = Pin("LED", Pin.OUT)
  51. ########################## Code ############################
  52. # test example class
  53. # test example function
  54. print(baz.button)
  55. # LED blinking
  56. while True:
  57. led.toggle()
  58. sleep_ms(500)
  59. led.toggle()
  60. sleep_ms(500)
  61. """
  62. ############################## Functions ##############################
  63. ############################## Run ##############################
  64. if __name__ == "__main__":
  65. main()