Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include "mbed.h"
  2.  
  3. //Serial pc( USBTX, USBRX );
  4.  
  5. //#define T 16
  6.  
  7.     DigitalIn butL( PTC9 );
  8.     DigitalIn butR( PTC12 );
  9.     DigitalIn butU( PTC11 );
  10.     DigitalIn butD( PTC10 );
  11.  
  12.     DigitalOut K_LED1( PTC1 );
  13.     DigitalOut K_LED2( PTC2 );
  14.     DigitalOut K_LED3( PTC3 );
  15.     DigitalOut K_LED4( PTC4 );
  16.     DigitalOut K_LED5( PTC5 );
  17.     DigitalOut K_LED6( PTC7 );
  18.  
  19.  
  20.  
  21.  
  22.  
  23. class MyLed : public DigitalOut {
  24. public:
  25.         uint8_t jas;
  26.         MyLed(PinName pin) : DigitalOut(pin){ jas = 0; }
  27.         void nastav jas(uint8_t ajas){
  28.             jas = ajas;
  29. //          for (int i = 0; i < T - 1; i++){
  30. //               if (i <= (T*jas) /100)
  31. //                  ledka = 1;
  32. //               else
  33. //                  ledka = 0;
  34. //                  }
  35. //      }
  36. };
  37.  
  38.     MyLed RGBledLr( PTB9 );
  39.     MyLed RGBledLg( PTB3 );
  40.     MyLed RGBledLb( PTB2 );
  41.  
  42.     MyLed RGBledRr( PTB19 );
  43.     MyLed RGBledRg( PTB18 );
  44.     MyLed RGBledRb( PTB11 );
  45.  
  46. void jas(DigitalOut *leds, unsigned char *jas, unsigned char pocetLed, unsigned char T){
  47.     for (unsigned char i = 0; i < T - 1; i++){
  48.         for (unsigned char j = 0; j < pocetLed; j++){
  49.             unsigned char time = T * jas[j] / 100;
  50.             led[j] = i < time ? true : false;
  51.         }
  52.         wait_ms( 1 );
  53.     }
  54. }
  55.  
  56. int main()
  57. {
  58.  
  59.     //pc.baud( 115200 );
  60.  
  61.     //pc.printf("Hello world\r\n");
  62.     DigitalOut redLEDS [] = {0, 0, 0, 0, 0, 0};
  63.     unsigned char jasArr[] = {0, 0, 0, 0, 0, 0};
  64.     DigitalOut leds[] = {RGBledLr, RGBledLg, RGBledLb, RGBledRr, RGBledRg, RGBledRb};
  65.  
  66.     unsigned char active = 0;
  67.     unsigned int wL = 0, wR = 0;
  68.  
  69.  
  70.     while ( 1 ){
  71.         if(!butL){
  72.             if(wL > 4){
  73.                 jasArr[active] = 0;
  74.                 active = active == 0 ? 5 : active - 1;
  75.                 jasArr[active] = 100;
  76.                 wL = 0;
  77.             }else{
  78.                 wL++;
  79.             }
  80.         }
  81.  
  82.         if(!butR){
  83.             if(wR > 4){
  84.                 jasArr[active] = 0;
  85.                 active = active == 5 ? 0 : active + 1;
  86.                 jasArr[active] = 100;
  87.                 wR = 0;
  88.             }else{
  89.                 wR++;
  90.             }
  91.         }
  92.  
  93.         if(!butU){
  94.             jasArr[active + 6] = jasArr[active + 6] < 100 ? jasArr[active + 6] + 1 : 100;
  95.         }
  96.  
  97.         if(!butD){
  98.             jasArr[active + 6] = jasArr[active + 6] > 0 ? jasArr[active + 6] - 1 : 0;
  99.         }
  100.  
  101.         jas(leds, jasArr, 6, 25);
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement