Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- //Serial pc( USBTX, USBRX );
- //#define T 16
- DigitalIn butL( PTC9 );
- DigitalIn butR( PTC12 );
- DigitalIn butU( PTC11 );
- DigitalIn butD( PTC10 );
- DigitalOut K_LED1( PTC1 );
- DigitalOut K_LED2( PTC2 );
- DigitalOut K_LED3( PTC3 );
- DigitalOut K_LED4( PTC4 );
- DigitalOut K_LED5( PTC5 );
- DigitalOut K_LED6( PTC7 );
- class MyLed : public DigitalOut {
- public:
- uint8_t jas;
- MyLed(PinName pin) : DigitalOut(pin){ jas = 0; }
- void nastav jas(uint8_t ajas){
- jas = ajas;
- // for (int i = 0; i < T - 1; i++){
- // if (i <= (T*jas) /100)
- // ledka = 1;
- // else
- // ledka = 0;
- // }
- // }
- };
- MyLed RGBledLr( PTB9 );
- MyLed RGBledLg( PTB3 );
- MyLed RGBledLb( PTB2 );
- MyLed RGBledRr( PTB19 );
- MyLed RGBledRg( PTB18 );
- MyLed RGBledRb( PTB11 );
- void jas(DigitalOut *leds, unsigned char *jas, unsigned char pocetLed, unsigned char T){
- for (unsigned char i = 0; i < T - 1; i++){
- for (unsigned char j = 0; j < pocetLed; j++){
- unsigned char time = T * jas[j] / 100;
- led[j] = i < time ? true : false;
- }
- wait_ms( 1 );
- }
- }
- int main()
- {
- //pc.baud( 115200 );
- //pc.printf("Hello world\r\n");
- DigitalOut redLEDS [] = {0, 0, 0, 0, 0, 0};
- unsigned char jasArr[] = {0, 0, 0, 0, 0, 0};
- DigitalOut leds[] = {RGBledLr, RGBledLg, RGBledLb, RGBledRr, RGBledRg, RGBledRb};
- unsigned char active = 0;
- unsigned int wL = 0, wR = 0;
- while ( 1 ){
- if(!butL){
- if(wL > 4){
- jasArr[active] = 0;
- active = active == 0 ? 5 : active - 1;
- jasArr[active] = 100;
- wL = 0;
- }else{
- wL++;
- }
- }
- if(!butR){
- if(wR > 4){
- jasArr[active] = 0;
- active = active == 5 ? 0 : active + 1;
- jasArr[active] = 100;
- wR = 0;
- }else{
- wR++;
- }
- }
- if(!butU){
- jasArr[active + 6] = jasArr[active + 6] < 100 ? jasArr[active + 6] + 1 : 100;
- }
- if(!butD){
- jasArr[active + 6] = jasArr[active + 6] > 0 ? jasArr[active + 6] - 1 : 0;
- }
- jas(leds, jasArr, 6, 25);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement