Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define USE_OCTOWS2811
- #include<OctoWS2811.h>
- #include <FastLED.h>
- #define NUM_STRIPS 8
- #define NUM_LEDS_PER_STRIP 64
- #define NUM_LEDS 512
- #define MAX_BRIGHTNESS 128
- CRGB leds[NUM_LEDS];
- #define elevator_size 4 // these are not changing during program execution
- #define top_floor 10 // but you can modify them each time you recompile
- #define floor_height 8 // to change the basic behaviour of your sketch
- int current_floor = 0; // these will be modified actively during program execution
- int which_floor = 0;
- int elevator_position = 0;
- void setup() {
- Serial.begin(9600);
- LEDS.addLeds<OCTOWS2811, RGB>(leds, NUM_LEDS_PER_STRIP);
- FastLED.setBrightness(MAX_BRIGHTNESS);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- for (int i = 0; i < elevator_size; i++){
- leds[i] = CRGB::Red;
- }
- FastLED.show();
- delay(2000);
- }
- void loop(){
- which_floor = random8(0, top_floor);
- Serial.print("current_floor = ");
- Serial.print(current_floor);
- Serial.print(", which_floor = ");
- Serial.println(which_floor);
- if (which_floor > current_floor) { // Going up
- for ( elevator_position = current_floor*floor_height;
- elevator_position <= which_floor*floor_height;
- elevator_position++) {
- Serial.print("elevator_position = ");
- Serial.println(elevator_position);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- for (int i = 0; i < elevator_size; i++) leds[elevator_position+i] = CRGB::Red;
- FastLED.show();
- delay(200);
- }
- }
- else { // Going down or just staying there
- for ( elevator_position = current_floor*floor_height;
- elevator_position >= which_floor*floor_height;
- elevator_position--) {
- Serial.print("elevator_position = ");
- Serial.println(elevator_position);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- for (int i = 0; i < elevator_size; i++) leds[elevator_position+i] = CRGB::Red;
- FastLED.show();
- delay(200);
- }
- }
- current_floor = which_floor;
- delay(2000); // or any value you want or replace 2000 with some random value !?
- }
Advertisement
Add Comment
Please, Sign In to add comment