Advertisement
Guest User

Arduino per katja

a guest
Jan 21st, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <FastLED.h>
  3. //#include <SFE_MicroOLED.h>
  4.  
  5.  
  6. #define NUM_LEDS 256  // How many LED in the strip
  7. #define PIN_LED   5  // Connect LED_Data to pin 5
  8.  
  9. #define PIN_RESET 9  // Connect RST to pin 9
  10. #define PIN_DC    8  // Connect DC to pin 8
  11. #define PIN_CS    10 // Connect Chip Select to pin 10
  12. #define DC_JUMPER 0 // Set to 0 for SPI
  13.  
  14. static uint8_t p = 0; // pivot led
  15. static uint8_t b = 255; // brightness
  16.  
  17. //MicroOLED oled(PIN_RESET, PIN_DC, PIN_CS); //SPI Object declaration
  18.  
  19. CRGB leds [NUM_LEDS];
  20.  
  21.  
  22. void setAllLED(uint8_t state) { for(int i = 0; i < NUM_LEDS; i++) { leds[i] = CHSV(0, 0, state%256 );}}
  23.  
  24.  
  25.  
  26. void setup() {
  27.   //oled.begin();     // Initialize the OLED
  28.   //oled.clear(PAGE); // Clear the display's internal memory
  29.   //oled.clear(ALL);  // Clear the library's display buffer
  30.   //oled.display();   // Display what's in the buffer (splashscreen)
  31.  
  32.   LEDS.addLeds<WS2812B,PIN_LED,RGB>(leds,NUM_LEDS);
  33.   LEDS.setBrightness(255);
  34.   pinMode(A3, OUTPUT);
  35. }
  36.  
  37. void loop() {
  38.     setAllLED(0);
  39.     leds[p] = CHSV(0, 0, b);
  40.     FastLED.show();
  41. //    printTitle("wait", 1);
  42.   // put your main code here, to run repeatedly:
  43.     delay(1000);
  44.     //printTitle("shoot", 1);
  45.     shootNow();
  46.     delay(2000);
  47.     if (p == NUM_LEDS) {
  48.       exit(0);
  49.     }
  50.     p = (++p)%NUM_LEDS;
  51.     //b = (++b)%256;
  52.    
  53.  
  54. }
  55. /*
  56. void printTitle(String title, int font)
  57. {
  58.   int middleX = oled.getLCDWidth() / 2;
  59.   int middleY = oled.getLCDHeight() / 2;
  60.  
  61.   oled.clear(PAGE);
  62.   oled.setFontType(font);
  63.   // Try to set the cursor in the middle of the screen
  64.   oled.setCursor(middleX - (oled.getFontWidth() * (title.length() / 2)),
  65.                  middleY - (oled.getFontHeight() / 2));
  66.   // Print the title:
  67.   oled.print(title);
  68.   oled.display();
  69. }
  70.  
  71. */
  72. void shootNow() {
  73.   const int high = 9;
  74.   const int low = 20;
  75.   const int gap = 7100;
  76.   const int np = 18;
  77.   const int pin = A3;
  78.  
  79.   digitalWrite(pin, LOW);
  80.   for(int i = 0 ; i < np ; i++) {
  81.     digitalWrite(pin, HIGH);
  82.     delayMicroseconds(high);
  83.     digitalWrite(pin, LOW);
  84.     delayMicroseconds(low);
  85.   }
  86.  
  87.   delayMicroseconds(gap);
  88.  
  89.   for(int i = 0 ; i < np ; i++) {
  90.     digitalWrite(pin, HIGH);
  91.     delayMicroseconds(high);
  92.     digitalWrite(pin, LOW);
  93.     delayMicroseconds(low);
  94.   }
  95.   digitalWrite(pin, LOW);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement