Rauthag

RGB Jas Blik()

Sep 30th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include "mbed.h"
  2. #define T 20
  3.  
  4. DigitalIn B1(PTC9);
  5. DigitalIn B2(PTC10);
  6. DigitalIn B3(PTC11);
  7. DigitalIn B4(PTC12);
  8.  
  9. const int rgb= 3;
  10.  
  11. class MyLed:public DigitalOut{
  12. public:
  13. uint8_t T1;
  14. MyLed(PinName Name);
  15. void nastav_T1(uint8_t jas);
  16. };
  17. MyLed::MyLed(PinName Name):DigitalOut(Name){};
  18.  
  19. void MyLed::nastav_T1(uint8_t jas){
  20. T1=(T*jas)/100;
  21. }
  22. void Blik(MyLed *pole, int velkost){
  23. for(int i=0; i<T; i++) {
  24. for(int j=0; j<velkost; j++){
  25. if((pole[j].T1 <= i) && (!pole[j].read()))
  26. pole[j].write(1);
  27. if(pole[j].T1 > i && pole[j].read())
  28. pole[j].write(0);
  29.  
  30. }
  31. wait_ms(1);
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. MyLed RGB[rgb]={(PTB2), (PTB3), (PTB9)};
  38.  
  39. bool pole[rgb];
  40. int pole2[rgb] = {10, 20, 30};
  41. bool pole3[rgb] ;
  42.  
  43. for(int i=0; i<rgb; i++){
  44. pole[i] = pole3[i] = false;
  45. RGB[i].nastav_T1(pole2[i]);
  46. }
  47. while (true) {
  48. Blik(RGB, rgb);
  49. if(!B2)
  50. pole[0] = true;
  51. if(!B3)
  52. pole[1] = true;
  53. if(!B4)
  54. pole[2] = true;
  55. for(int z = 0; z<rgb; z++){
  56. if((pole[z]) && (!pole3[z])) {
  57. RGB[z].nastav_T1(++pole2[z]);
  58. if(pole2[z]>99) pole3[z] = true;
  59. }
  60. if((pole[z]) && (pole3[z])) {
  61. RGB[z].nastav_T1(--pole2[z]);
  62. if(pole2[z]<1) pole3[z] = false;
  63. }
  64. }
  65. if(!B1){
  66. for(int i=0; i<rgb; i++){
  67. pole[i] = false;
  68. }
  69. }
  70. wait_ms(1);
  71. }
  72.  
  73.  
  74. }
Add Comment
Please, Sign In to add comment