Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SD.h>
- #include "FastLED.h"
- // How many leds in your strip?
- #define NUM_LEDS 60
- // For led chips like Neopixels, which have a data line, ground, and power, you just
- // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
- // ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
- #define DATA_PIN 6
- #define CLOCK_PIN 13
- int rcPin = 2; // PWM signal arduino pin
- int Speed = 0; // Receiver channel 1 pwm value
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- void setup() {
- FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS);
- pinMode(rcPin, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- // First slide the led from outer ends towards the middle
- // Move the dots to the 7th LED inwards from each end
- for(int i = 0; i < (NUM_LEDS / 8) - 1; i++) {
- // Set the i'th led to red
- //Start with 1st LED and move inwards
- leds[i] = CRGB::DarkViolet ;
- //while also having opposite end LED move inwards
- leds[NUM_LEDS - i -1] = CRGB::DarkViolet ;
- // Show the leds
- FastLED.show();
- //erase drawn dots
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and move the dots inwards by one
- delay(Speed);
- //when we get to the 7th LED inwards from each end
- //check the pin hooked up to the rc receiver to check
- //PW size on the low side
- //the PW LOW is longest at lowest throttle position
- //to give a longer delay and slow the pattern down
- //PW is shortest at the highest position-full throttle
- //to give a shorter delay and speed up the pattern
- //shortest LOW is approx 19950
- //longest LOW is approx 20800
- //I alter the data to give a delay time range of 2-36
- //2 at full throttle and 36 at lowest throttle position
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- //show me the value of Speed
- Serial.println(Speed);
- //beginning at the 8th LED inwards on each end
- //we begin where we left off from the prev for loop
- //and stop at the 14th LED on each end.
- for(int i= 8;i < (NUM_LEDS / 4) - 1; i++) {
- // Set the i'th led to red
- leds[i] = CRGB::DarkViolet ;
- leds[NUM_LEDS - i -1] = CRGB::DarkViolet ;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- Serial.println(Speed);
- //now we've reached midpoint for each end
- for(int i= 15;i < (NUM_LEDS / 3) +2; i++) {
- // Set the i'th led to red
- leds[i] = CRGB::DarkViolet ;
- leds[NUM_LEDS - i -1] = CRGB::DarkViolet ;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- Serial.println(Speed);
- for(int i= 22;i < (NUM_LEDS / 2) -1; i++) {
- // Set the i'th led to red
- leds[i] = CRGB::DarkViolet ;
- leds[NUM_LEDS - i -1] = CRGB::DarkViolet ;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- Serial.println(Speed);
- // Now go in the other direction.
- //we reached the middle, now let's go back towards the ends
- for(int i = (NUM_LEDS / 2); i > 22; i--) {
- // Set the i'th led to red
- leds[i] = CRGB::Red;
- leds[NUM_LEDS - i -1] = CRGB::Red;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- for(int i = 22; i > 15; i--) {
- // Set the i'th led to red
- leds[i] = CRGB::Red;
- leds[NUM_LEDS - i -1] = CRGB::Red;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- Serial.println(Speed);
- for(int i = 15; i > 8; i--) {
- // Set the i'th led to red
- leds[i] = CRGB::Red;
- leds[NUM_LEDS - i -1] = CRGB::Red;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- Serial.println(Speed);
- for(int i = 8; i > 0; i--) {
- // Set the i'th led to red
- leds[i] = CRGB::Red;
- leds[NUM_LEDS - i -1] = CRGB::Red;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[NUM_LEDS - i -1] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(Speed);
- }
- Speed = pulseIn(rcPin, LOW);
- Speed= (Speed -19900)/25;
- if (Speed <=0) {
- Speed=0;
- }
- Serial.println(Speed);
- }
- //go back to the first LED's on each end and start over
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement