TS_Builder

Elevator_Test_R1

Mar 9th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. //#define USE_OCTOWS2811
  2. //#include<OctoWS2811.h>
  3. #include <FastLED.h>
  4.  
  5. #define NUM_STRIPS 1 // old value 8
  6. #define NUM_LEDS_PER_STRIP 45 // old value 64
  7. #define NUM_LEDS 45 // old value 512
  8. #define MAX_BRIGHTNESS 128
  9. #define DATA_PIN 6 // Added Data_pin Definition
  10.  
  11. CRGB leds[NUM_LEDS];
  12.  
  13. #define elevator_size 4 // these are not changing during program execution
  14. #define top_floor 10 // but you can modify them each time you recompile
  15. #define floor_height 8 // to change the basic behaviour of your sketch
  16.  
  17. int current_floor = 0; // these will be modified actively during program execution
  18. int which_floor = 0;
  19. int elevator_position = 0;
  20.  
  21. void setup() {
  22.  
  23. Serial.begin(9600);
  24.  
  25. //LEDS.addLeds<OCTOWS2811, RGB>(leds, NUM_LEDS_PER_STRIP); //Original code
  26. FastLED.addLeds<NEOPIXEL, RGB>(leds, NUM_LEDS); //Changed From OCTOWS2811 to FastLED - Changed LEDS.addleds to FastLED.addleds - FastLED changed to Neopixel, CRGB
  27. FastLED.setBrightness(MAX_BRIGHTNESS);
  28. fill_solid(leds, NUM_LEDS, CRGB::Black);
  29. for (int i = 0; i < elevator_size; i++){
  30. leds[i] = CRGB::Red;
  31. }
  32. FastLED.show();
  33. delay(2000);
  34.  
  35. }
  36. void loop(){
  37.  
  38. which_floor = random8(0, top_floor);
  39.  
  40. Serial.print("current_floor = "); // added ln
  41. Serial.print(current_floor); // added ln
  42. Serial.print(", which_floor = "); // added ln
  43. Serial.println(which_floor);
  44.  
  45. if (which_floor > current_floor) { // Going up
  46. for ( elevator_position = current_floor*floor_height;
  47. elevator_position <= which_floor*floor_height;
  48. elevator_position++) {
  49.  
  50. Serial.print("elevator_position = ");
  51. Serial.println(elevator_position);
  52.  
  53. fill_solid(leds, NUM_LEDS, CRGB::Black);
  54. for (int i = 0; i < elevator_size; i++) leds[elevator_position+i] = CRGB::Red;
  55. FastLED.show();
  56. delay(200);
  57. }
  58. }
  59.  
  60. else { // Going down or just staying there
  61. for ( elevator_position = current_floor*floor_height;
  62. elevator_position >= which_floor*floor_height;
  63. elevator_position--) {
  64.  
  65. Serial.print("elevator_position = ");
  66. Serial.println(elevator_position);
  67.  
  68. fill_solid(leds, NUM_LEDS, CRGB::Black);
  69. for (int i = 0; i < elevator_size; i++) leds[elevator_position+i] = CRGB::Red;
  70. FastLED.show();
  71. delay(200);
  72. }
  73. }
  74.  
  75. current_floor = which_floor;
  76.  
  77. delay(2000); // or any value you want or replace 2000 with some random value !?
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment