Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- #include <LedCube.h>
- #define SIZE 3
- #define COLS (SIZE*SIZE)
- int RECV_PIN = 4;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- // Initalize our LED columns (positive)
- byte LEDPin[] = {5,8,11,6,9,12,7,10,13};
- // Initalize the LED layers (ground)
- byte LayerPin[] = {A3,A4,A5};
- LedCube cube(3, LayerPin, LEDPin);
- int count = 0;
- int pin = 0;
- int layer = 0;
- boolean PinState = 0;
- int LPin = 0;
- void LayersOff() { // функция для выключения всех слоёв
- for(int layer = 0; layer < 3; layer++){
- digitalWrite(LayerPin[layer], LOW);
- }
- }
- void LayersOn() { // функция для включения всех слоёв
- for(int layer = 0; layer < 3; layer++){
- digitalWrite(LayerPin[layer], HIGH);
- }
- }
- void PinOnOff() {
- PinState = !PinState;
- digitalWrite(LEDPin[pin],PinState);
- }
- void LayerUP(int layer) { // включаем на 1 слой выше
- for (LPin = 0; LPin < layer; LPin++){
- digitalWrite(LayerPin[LPin],HIGH);
- }
- }
- void setup() {
- // pinMode(ButPin, INPUT); // Задаем как вход
- Serial.begin(9600);
- // pinMode(IRpin, INPUT);
- irrecv.enableIRIn(); // Start the receiver
- // Set up LED columns as output
- for(int pin = 0; pin < 10 ; pin++ ){
- pinMode(LEDPin[pin],OUTPUT);
- digitalWrite(LEDPin[pin],LOW);
- }
- // Set up LED Layers as output
- for(int layer = 0; layer < 3; layer++){
- pinMode(LayerPin[layer], OUTPUT);
- }
- LayersOff();
- }
- void loop() {
- if (irrecv.decode(&results)) {
- Serial.println(results.value);
- switch (results.value) {
- case 0xFF6897: // button 0
- Serial.println("pin 0");
- pin = 0;
- PinOnOff();
- break;
- case 0xFF30CF: // button 1
- Serial.println("pin 1");
- pin = 1;
- PinOnOff();
- break;
- case 0xFF18E7: // button 2
- Serial.println("pin 2");
- pin = 2;
- PinOnOff();
- break;
- case 0xFF7A85: // button 3
- Serial.println("pin 3");
- pin = 3;
- PinOnOff();
- break;
- case 0xFF10EF: // button 4
- Serial.println("pin 4");
- pin = 4;
- PinOnOff();
- break;
- case 0xFF38C7: // button 5
- Serial.println("pin 5");
- pin = 5;
- PinOnOff();
- break;
- case 0xFF5AA5: // button 6
- Serial.println("pin 6");
- pin = 6;
- PinOnOff();
- break;
- case 0xFF42BD: // button 7
- Serial.println("pin 7");
- pin = 7;
- PinOnOff();
- break;
- case 0xFF4AB5: // button 8
- Serial.println("pin 8");
- pin = 8;
- PinOnOff();
- break;
- case 0xFF52AD: // button 9
- Serial.println("All is UP!");
- PinState = !PinState;
- for(int pin = 0; pin < 10 ; pin++ ){
- digitalWrite(LEDPin[pin],PinState);
- }
- break;
- case 0xFFE01F: //vol-
- if (pin < 0) {
- pin = 8;
- int count = 0;
- while (count < 3) {
- PinOnOff();
- delay(50);
- count++;
- }
- } else {
- PinOnOff();
- pin = pin--;
- }
- PinOnOff();
- Serial.print("pin - | ");
- Serial.println(pin);
- break;
- case 0xFFA857: //vol+
- Serial.print("pin + | ");
- Serial.println(pin);
- if (pin > 8) {
- pin = 8;
- int count = 0;
- while (count < 3) {
- PinOnOff();
- delay(50);
- count++;
- }
- } else {
- PinOnOff();
- pin = ++pin;
- }
- PinOnOff();
- break;
- case 0xFFA25D: //CH-
- if (layer < 0) {
- layer = 0;
- LayersOff();
- int count = 0;
- while (count < 3) {
- LayersOn();
- delay(50);
- LayersOff();
- delay(50);
- count++;
- }
- } else {
- digitalWrite(LayerPin[layer],LOW);
- layer = layer--;
- }
- Serial.print("layer - | ");
- Serial.println(layer);
- break;
- case 0xFFE21D: //CH+
- if (layer > 2) {
- layer = 3;
- int count = 0;
- while (count < 3) {
- LayersOff();
- delay(50);
- LayersOn();
- delay(50);
- count++;
- }
- } else {
- layer = layer++;
- }
- LayerUP(layer);
- Serial.print("layer + | ");
- Serial.println(layer);
- break;
- case 0xFF22DD: // PREV
- LayersOff();
- if (layer == 0) {
- layer = 2;
- }
- else {
- layer = layer--;
- }
- digitalWrite(LayerPin[layer],HIGH);
- Serial.print("prev layer | ");
- Serial.println(layer);
- break;
- case 0xFF02FD: // NEXT
- LayersOff();
- if (layer >= 2) {
- layer = 0;
- }
- else {
- layer = layer++;
- }
- digitalWrite(LayerPin[layer],HIGH);
- Serial.print("next layer | ");
- Serial.println(layer);
- break;
- case 0xFF629D: //CH
- Serial.println("Layers Off");
- LayersOff();
- layer = -1;
- break;
- case 0xFFC23D: //PAUSE
- Serial.println("Layers On");
- LayersOn();
- break;
- case 0xFF906F: // EQ
- Serial.print("pin = ");
- Serial.println(pin);
- Serial.print("layer = ");
- Serial.println(layer);
- delay(100);
- cube.enableBuffer(false);
- // light one level at a time, increasing speed each time
- for(byte d=25; d>2; d-=2) {
- for(byte r=0; r<cube.getLevels(); r++) {
- cube.lightLevel(r,d);
- }
- }
- // single random light at a time
- cube.randomLight(random(25,100),100);
- // random column drop
- for(byte x=0; x<=15; x++) {
- cube.lightDrop(random(0,cube.getCols()), random(50,150));
- }
- // circle around cube at a random level
- for(byte x=0; x<=5; x++) {
- cube.lightPerimeter(random(0,cube.getLevels()), random(1,5), random(25,100));
- }
- // random columns
- cube.randomColumn(25);
- // turn off a single column randomly
- cube.enableBuffer();
- for(byte c=0; c<25; c++)
- {
- cube.fillBuffer();
- cube.invertBuffer();
- cube.randomColumn();
- cube.drawBuffer(10);
- }
- cube.enableBuffer(false);
- // cols in and out
- for(byte c=1, d=0; c<=36; c++)
- {
- if(c%2 == 0){
- for(d=0; d<20; d++) {
- cube.lightColumn(2,1);
- cube.lightColumn(4,1);
- cube.lightColumn(6,1);
- cube.lightColumn(8,1);
- }
- } else if(c%4 == 1) {
- for(d=0; d<30; d++) {
- cube.lightColumn(1,1);
- cube.lightColumn(3,1);
- cube.lightColumn(7,1);
- cube.lightColumn(9,1);
- }
- } else {
- for(d=0; d<70; d++) {
- cube.lightColumn(5,1);
- }
- }
- }
- // diamond and box
- byte diamond[] = {0,4, 1,1, 1,3, 1,4, 1,5, 1,7, 2,4};
- byte box[] = {0,0, 0,1, 0,2, 0,3, 0,5, 0,6, 0,7, 0,8, 1,1, 1,0, 1,2, 1,6, 1,8, 2,0, 2,1, 2,2, 2,3, 2,5, 2,6, 2,7, 2,8};
- cube.lightSequence(box, sizeof(box), 200);
- cube.lightSequence(diamond, sizeof(diamond), 400);
- // helicopter effect
- cube.enableBuffer();
- byte topSeq[8] = {0,3,6,7,8,5,2,1};
- byte botSeq[8] = {8,5,2,1,0,3,6,7};
- for(byte r = 0; r<7; r++){
- for(byte s= 0; s<8; s++){
- cube.clearBuffer();
- cube.lightOn(0,botSeq[s]);
- cube.lightOn(1,4);
- cube.lightOn(2,topSeq[s]);
- cube.drawBuffer(20);
- }
- }
- // turn off one light at a time
- cube.fillBuffer();
- cube.drawBuffer(25);
- for(byte w=0, l, c; w<27; ){
- l = random(0,cube.getLevels());
- c = random(0,cube.getCols());
- if(cube.getBufferAt(l,c)){
- cube.lightOff(l,c);
- cube.drawBuffer(15+w*2);
- w++;
- }
- }
- break;
- }
- irrecv.resume(); // Receive the next value
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement