Cześć wszystkim! - Wersja do druku +- Arduino Polska Forum (https://forum.arduinopolska.pl) +-- Dział: Start (https://forum.arduinopolska.pl/dzial-start) +--- Dział: Przywitanie (https://forum.arduinopolska.pl/dzial-przywitanie) +--- Wątek: Cześć wszystkim! (/watek-cze%C5%9B%C4%87-wszystkim--2752) |
Cześć wszystkim! - johnyNapalm - 13-01-2019 Jestem studentem informatyki (jeszcze przez miesiąc), właśnie piszę pracę inżynierską opartą na arduino więc mam kilka pytań i mam nadzieje że tutaj otrzymam na nie odpowiedzi . Z góry przepraszam za małą wiedzę i dziękuję za pomoc . RE: Cześć wszystkim! - Maciejelektronik - 14-01-2019 Witam mam tu kod na sterowanie diodami ws2812 za pomoca pilota IR wszystko dziala jak nalezy #include <IRremote.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 6 #define NUM_LEDS 60 #define BRIGHTNESS 50 #define PIN 6 // numer portu do ktorego podlaczony jest pasek #define irPin 7 #define ILOSCDIOD 31 // ilosc diod w pasku Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ILOSCDIOD, PIN, NEO_GRB + NEO_KHZ800); IRrecv irrecv(irPin); decode_results results; void setup() { Serial.begin(9600); pixels.begin(); // Inicjalizacja biblioteki irrecv.enableIRIn(); // uruchomienie odbiornika IR #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif{ strip.setBrightness(BRIGHTNESS); strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { if (irrecv.decode(&results)) { switch (results.value) { case 0xFFE01F: //przycisk off off(); break; case 0xFF30CF: //przycisk nr1 red(); break; case 0xFF18E7: //przycisk nr2 green(); break; case 0xFF7A85: //przycisk nr3 blue(); break; case 0xFF10EF: //przycisk nr4 yellow(); break; case 0xFF38C7 : //przycisk nr5 white(); break; case 0xFF5AA5 : //przycisk nr6 violet(); break; } irrecv.resume(); } } // Some example procedures showing how to display to the pixels: colorWipe(strip.Color(255, 0, 0), 50); // Red colorWipe(strip.Color(0, 255, 0), 50); // Green colorWipe(strip.Color(0, 0, 255), 50); // Blue colorWipe(strip.Color(0, 0, 0, 255), 50); // White whiteOverRainbow(20,75,5); pulseWhite(5); // fullWhite(); // delay(2000); rainbowFade2White(3,3,1); } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } void pulseWhite(uint8_t wait) { for(int j = 0; j < 256 ; j++){ for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) ); } delay(wait); strip.show(); } for(int j = 255; j >= 0 ; j--){ for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) ); } delay(wait); strip.show(); } } void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops) { float fadeMax = 100.0; int fadeVal = 0; uint32_t wheelVal; int redVal, greenVal, blueVal; for(int k = 0 ; k < rainbowLoops ; k ++){ for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel for(int i=0; i< strip.numPixels(); i++) { wheelVal = Wheel(((i * 256 / strip.numPixels()) + j) & 255); redVal = red(wheelVal) * float(fadeVal/fadeMax); greenVal = green(wheelVal) * float(fadeVal/fadeMax); blueVal = blue(wheelVal) * float(fadeVal/fadeMax); strip.setPixelColor( i, strip.Color( redVal, greenVal, blueVal ) ); } //First loop, fade in! if(k == 0 && fadeVal < fadeMax-1) { fadeVal++; } //Last loop, fade out! else if(k == rainbowLoops - 1 && j > 255 - fadeMax ){ fadeVal--; } strip.show(); delay(wait); } } delay(500); for(int k = 0 ; k < whiteLoops ; k ++){ for(int j = 0; j < 256 ; j++){ for(uint16_t i=0; i < strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) ); } strip.show(); } delay(2000); for(int j = 255; j >= 0 ; j--){ for(uint16_t i=0; i < strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0,0,0, neopix_gamma[j] ) ); } strip.show(); } } delay(500); } void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength ) { if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1; int head = whiteLength - 1; int tail = 0; int loops = 3; int loopNum = 0; static unsigned long lastTime = 0; while(true){ for(int j=0; j<256; j++) { for(uint16_t i=0; i<strip.numPixels(); i++) { if((i >= tail && i <= head) || (tail > head && i >= tail) || (tail > head && i <= head) ){ strip.setPixelColor(i, strip.Color(0,0,0, 255 ) ); } else{ strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } } if(millis() - lastTime > whiteSpeed) { head++; tail++; if(head == strip.numPixels()){ loopNum++; } lastTime = millis(); } if(loopNum == loops) return; head%=strip.numPixels(); tail%=strip.numPixels(); strip.show(); delay(wait); } } } void fullWhite() { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0,0,0, 255 ) ); } strip.show(); } // Slightly different, this makes the rainbow equally distributed throughout void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256 * 5; j++) { // 5 cycles of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0); } uint8_t red(uint32_t c) { return (c >> 16); } uint8_t green(uint32_t c) { return (c >> 8); } uint8_t blue(uint32_t c) { return ©; } ////////////////////////// funkcje zawierające skladowe kolorow //////////////////// void red() //funkcja koloru czerwonego { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 255, 0, 0); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } void green() //funkcja koloru zielonego { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 0, 255, 0); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } void blue() //funkcja koloru niebieskiego { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 0, 0, 255); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } void yellow() //funkcja koloru żółtego { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 255, 255, 0); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } void white() //funkcja koloru białego { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 255, 255, 255); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } void violet() //funkcja koloru fioletowego { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 204, 0, 102); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } void off() //funkcja wylaczenia paska { for(int i=0; i<31; i++) { pixels.setPixelColor(i, 0, 0, 0); // Dioda "i" oraz odpowiednie skladowe RGB pixels.show(); // Wysylanie danych do lancucha } } Lecz chcialbym sterowac pilotem nie tylko pojedynczymi kolorami lecz efektami kolorow jak w bibliotece np: FAST LED tutaj daje przykladowy kod #include <FastLED.h> #define LED_PIN 3 #define COLOR_ORDER GRB #define CHIPSET WS2811 #define BRIGHTNESS 64 // Helper functions for an two-dimensional XY matrix of pixels. // Simple 2-D demo code is included as well. // // XY(x,y) takes x and y coordinates and returns an LED index number, // for use like this: leds[ XY(x,y) ] == CRGB::Red; // No error checking is performed on the ranges of x and y. // // XYsafe(x,y) takes x and y coordinates and returns an LED index number, // for use like this: leds[ XY(x,y) ] == CRGB::Red; // Error checking IS performed on the ranges of x and y, and an // index of "-1" is returned. Special instructions below // explain how to use this without having to do your own error // checking every time you use this function. // This is a slightly more advanced technique, and // it REQUIRES SPECIAL ADDITIONAL setup, described below. // Params for width and height const uint8_t kMatrixWidth = 16; const uint8_t kMatrixHeight = 16; // Param for different pixel layouts const bool kMatrixSerpentineLayout = true; // Set 'kMatrixSerpentineLayout' to false if your pixels are // laid out all running the same way, like this: // // 0 > 1 > 2 > 3 > 4 // | // .----<----<----<----' // | // 5 > 6 > 7 > 8 > 9 // | // .----<----<----<----' // | // 10 > 11 > 12 > 13 > 14 // | // .----<----<----<----' // | // 15 > 16 > 17 > 18 > 19 // // Set 'kMatrixSerpentineLayout' to true if your pixels are // laid out back-and-forth, like this: // // 0 > 1 > 2 > 3 > 4 // | // | // 9 < 8 < 7 < 6 < 5 // | // | // 10 > 11 > 12 > 13 > 14 // | // | // 19 < 18 < 17 < 16 < 15 // // Bonus vocabulary word: anything that goes one way // in one row, and then backwards in the next row, and so on // is call "boustrophedon", meaning "as the ox plows." // This function will return the right 'led index number' for // a given set of X and Y coordinates on your matrix. // IT DOES NOT CHECK THE COORDINATE BOUNDARIES. // That's up to you. Don't pass it bogus values. // // Use the "XY" function like this: // // for( uint8_t x = 0; x < kMatrixWidth; x++) { // for( uint8_t y = 0; y < kMatrixHeight; y++) { // // // Here's the x, y to 'led index' in action: // leds[ XY( x, y) ] = CHSV( random8(), 255, 255); // // } // } // // uint16_t XY( uint8_t x, uint8_t y) { uint16_t i; if( kMatrixSerpentineLayout == false) { i = (y * kMatrixWidth) + x; } if( kMatrixSerpentineLayout == true) { if( y & 0x01) { // Odd rows run backwards uint8_t reverseX = (kMatrixWidth - 1) - x; i = (y * kMatrixWidth) + reverseX; } else { // Even rows run forwards i = (y * kMatrixWidth) + x; } } return i; } // Once you've gotten the basics working (AND NOT UNTIL THEN!) // here's a helpful technique that can be tricky to set up, but // then helps you avoid the needs for sprinkling array-bound-checking // throughout your code. // // It requires a careful attention to get it set up correctly, but // can potentially make your code smaller and faster. // // Suppose you have an 8 x 5 matrix of 40 LEDs. Normally, you'd // delcare your leds array like this: // CRGB leds[40]; // But instead of that, declare an LED buffer with one extra pixel in // it, "leds_plus_safety_pixel". Then declare "leds" as a pointer to // that array, but starting with the 2nd element (id=1) of that array: // CRGB leds_with_safety_pixel[41]; // CRGB* const leds( leds_plus_safety_pixel + 1); // Then you use the "leds" array as you normally would. // Now "leds[0..N]" are aliases for "leds_plus_safety_pixel[1..(N+1)]", // AND leds[-1] is now a legitimate and safe alias for leds_plus_safety_pixel[0]. // leds_plus_safety_pixel[0] aka leds[-1] is now your "safety pixel". // // Now instead of using the XY function above, use the one below, "XYsafe". // // If the X and Y values are 'in bounds', this function will return an index // into the visible led array, same as "XY" does. // HOWEVER -- and this is the trick -- if the X or Y values // are out of bounds, this function will return an index of -1. // And since leds[-1] is actually just an alias for leds_plus_safety_pixel[0], // it's a totally safe and legal place to access. And since the 'safety pixel' // falls 'outside' the visible part of the LED array, anything you write // there is hidden from view automatically. // Thus, this line of code is totally safe, regardless of the actual size of // your matrix: // leds[ XYsafe( random8(), random8() ) ] = CHSV( random8(), 255, 255); // // The only catch here is that while this makes it safe to read from and // write to 'any pixel', there's really only ONE 'safety pixel'. No matter // what out-of-bounds coordinates you write to, you'll really be writing to // that one safety pixel. And if you try to READ from the safety pixel, // you'll read whatever was written there last, reglardless of what coordinates // were supplied. #define NUM_LEDS (kMatrixWidth * kMatrixHeight) CRGB leds_plus_safety_pixel[ NUM_LEDS + 1]; CRGB* const leds( leds_plus_safety_pixel + 1); uint16_t XYsafe( uint8_t x, uint8_t y) { if( x >= kMatrixWidth) return -1; if( y >= kMatrixHeight) return -1; return XY(x,y); } // Demo that USES "XY" follows code below void loop() { uint32_t ms = millis(); int32_t yHueDelta32 = ((int32_t)cos16( ms * (27/1) ) * (350 / kMatrixWidth)); int32_t xHueDelta32 = ((int32_t)cos16( ms * (39/1) ) * (310 / kMatrixHeight)); DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768); if( ms < 5000 ) { FastLED.setBrightness( scale8( BRIGHTNESS, (ms * 256) / 5000)); } else { FastLED.setBrightness(BRIGHTNESS); } FastLED.show(); } void DrawOneFrame( byte startHue8, int8_t yHueDelta8, int8_t xHueDelta8) { byte lineStartHue = startHue8; for( byte y = 0; y < kMatrixHeight; y++) { lineStartHue += yHueDelta8; byte pixelHue = lineStartHue; for( byte x = 0; x < kMatrixWidth; x++) { pixelHue += xHueDelta8; leds[ XY(x, y)] = CHSV( pixelHue, 255, 255); } } } void setup() { FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050); FastLED.setBrightness( BRIGHTNESS ); } POMÓŻCIE !! RE: Cześć wszystkim! - error105 - 14-01-2019 W czym ? |