PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LED.h 995B

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef LED_H
  2. #define LED_H
  3. /*
  4. * File Purpose
  5. * The purpose of this file is to create a simple interface for turning on and off an led
  6. * And for threading led function so that you can make an led blink for a specified amount of duty at any frequency
  7. */
  8. #include <stdint.h>
  9. #include <TeensyThreads.h>
  10. #include "Runnable.h"
  11. class LED : public Runnable{
  12. private:
  13. // Digital pin
  14. uint8_t pin;
  15. // Track state so the program knows if the LED is ON or OFF
  16. bool state;
  17. // Timing Variables
  18. float duration;
  19. float period;
  20. float duty;
  21. // Thread object
  22. std::thread *blinkThread;
  23. protected:
  24. // Runnable function that we need to implement
  25. void runTarget(void *arg);
  26. public:
  27. // Constructor/Destructor
  28. LED(uint8_t pin);
  29. ~LED();
  30. // Turn on and off LED, volatile for threading use
  31. void turnOn() volatile;
  32. void turnOff() volatile;
  33. // Start thread that will last for duration
  34. void startBlinking(float duration, float period, float duty);
  35. };
  36. #endif // LED_H