Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- #define T 20
- DigitalIn B1(PTC9);
- DigitalIn B2(PTC10);
- DigitalIn B3(PTC11);
- DigitalIn B4(PTC12);
- const int rgb= 3;
- class MyLed:public DigitalOut{
- public:
- uint8_t T1;
- MyLed(PinName Name);
- void nastav_T1(uint8_t jas);
- };
- MyLed::MyLed(PinName Name):DigitalOut(Name){};
- void MyLed::nastav_T1(uint8_t jas){
- T1=(T*jas)/100;
- }
- void Blik(MyLed *pole, int velkost){
- for(int i=0; i<T; i++) {
- for(int j=0; j<velkost; j++){
- if((pole[j].T1 <= i) && (!pole[j].read()))
- pole[j].write(1);
- if(pole[j].T1 > i && pole[j].read())
- pole[j].write(0);
- }
- wait_ms(1);
- }
- }
- int main()
- {
- MyLed RGB[rgb]={(PTB2), (PTB3), (PTB9)};
- bool pole[rgb];
- int pole2[rgb] = {10, 20, 30};
- bool pole3[rgb] ;
- for(int i=0; i<rgb; i++){
- pole[i] = pole3[i] = false;
- RGB[i].nastav_T1(pole2[i]);
- }
- while (true) {
- Blik(RGB, rgb);
- if(!B2)
- pole[0] = true;
- if(!B3)
- pole[1] = true;
- if(!B4)
- pole[2] = true;
- for(int z = 0; z<rgb; z++){
- if((pole[z]) && (!pole3[z])) {
- RGB[z].nastav_T1(++pole2[z]);
- if(pole2[z]>99) pole3[z] = true;
- }
- if((pole[z]) && (pole3[z])) {
- RGB[z].nastav_T1(--pole2[z]);
- if(pole2[z]<1) pole3[z] = false;
- }
- }
- if(!B1){
- for(int i=0; i<rgb; i++){
- pole[i] = false;
- }
- }
- wait_ms(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement