Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <FastLED.h>
- //#include <SFE_MicroOLED.h>
- #define NUM_LEDS 256 // How many LED in the strip
- #define PIN_LED 5 // Connect LED_Data to pin 5
- #define PIN_RESET 9 // Connect RST to pin 9
- #define PIN_DC 8 // Connect DC to pin 8
- #define PIN_CS 10 // Connect Chip Select to pin 10
- #define DC_JUMPER 0 // Set to 0 for SPI
- static uint8_t p = 0; // pivot led
- static uint8_t b = 255; // brightness
- //MicroOLED oled(PIN_RESET, PIN_DC, PIN_CS); //SPI Object declaration
- CRGB leds [NUM_LEDS];
- void setAllLED(uint8_t state) { for(int i = 0; i < NUM_LEDS; i++) { leds[i] = CHSV(0, 0, state%256 );}}
- void setup() {
- //oled.begin(); // Initialize the OLED
- //oled.clear(PAGE); // Clear the display's internal memory
- //oled.clear(ALL); // Clear the library's display buffer
- //oled.display(); // Display what's in the buffer (splashscreen)
- LEDS.addLeds<WS2812B,PIN_LED,RGB>(leds,NUM_LEDS);
- LEDS.setBrightness(255);
- pinMode(A3, OUTPUT);
- }
- void loop() {
- setAllLED(0);
- leds[p] = CHSV(0, 0, b);
- FastLED.show();
- // printTitle("wait", 1);
- // put your main code here, to run repeatedly:
- delay(1000);
- //printTitle("shoot", 1);
- shootNow();
- delay(2000);
- if (p == NUM_LEDS) {
- exit(0);
- }
- p = (++p)%NUM_LEDS;
- //b = (++b)%256;
- }
- /*
- void printTitle(String title, int font)
- {
- int middleX = oled.getLCDWidth() / 2;
- int middleY = oled.getLCDHeight() / 2;
- oled.clear(PAGE);
- oled.setFontType(font);
- // Try to set the cursor in the middle of the screen
- oled.setCursor(middleX - (oled.getFontWidth() * (title.length() / 2)),
- middleY - (oled.getFontHeight() / 2));
- // Print the title:
- oled.print(title);
- oled.display();
- }
- */
- void shootNow() {
- const int high = 9;
- const int low = 20;
- const int gap = 7100;
- const int np = 18;
- const int pin = A3;
- digitalWrite(pin, LOW);
- for(int i = 0 ; i < np ; i++) {
- digitalWrite(pin, HIGH);
- delayMicroseconds(high);
- digitalWrite(pin, LOW);
- delayMicroseconds(low);
- }
- delayMicroseconds(gap);
- for(int i = 0 ; i < np ; i++) {
- digitalWrite(pin, HIGH);
- delayMicroseconds(high);
- digitalWrite(pin, LOW);
- delayMicroseconds(low);
- }
- digitalWrite(pin, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement