Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
Cathprotech
Published © GPL3+

Minecraft Nightlight

A simple Minecraft Ore Cube with and Arduino Pro Mini, RGB LED, tilt switch and USB power connection. The cube changes colour when tilted.

BeginnerWork in progress515
Minecraft Nightlight

Things used in this project

Hardware components

Arduino Mini Pro - ATmega168 5V
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Tilt Switch
×1
SparkFun USB Mini-B Breakout
SparkFun USB Mini-B Breakout
×1

Story

Read more

Code

Mincraft Cube Nightlight

C/C++
int redpin = 9; //select the pin for the red LED
int greenpin = 10;// select the pin for the green LED
int bluepin = 11; // select the pin for the  blue LED
const int buttonPin = 2;    // the number of the pushbutton pin
int buttonState;             // the current reading from the input pin
int count = 0;
int r = 0;
int g = 0;
int b = 0;

void setup() {
    pinMode(buttonPin, INPUT_PULLUP); 
    pinMode(redpin, OUTPUT); 
    pinMode(bluepin, OUTPUT); 
    pinMode(greenpin, OUTPUT); 
    Serial.begin(115200);
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);  //  Set intial state to all off
    }

void loop() {

  // read the state of the switch into a local variable:
  int buttonState = digitalRead(buttonPin);
    if(buttonState == LOW){
      delay(500);
      count++;
      }
    if (count >=13){
       count=0;
       }
        if (count==0){
          blacktodiamond();
          count=1;
       }
        if (count==1){
          diamond();
        }
        if (count==2){
          diamondtoiron();
          count=3;
        }
        if (count==3){
          iron();
        }
        if (count==4){
          irontoemerald();
          count=5;
        }
        if (count==5){
          emerald();
        }
        if (count==6){
          emeraldtolapis();
          count=7;
        }
        if (count==7){
          lapis();
        }
        if (count==8){
          lapistoredstone();
          count=9;
        }
        if (count==9){
          redstone();
        }
        if (count==10){
          redstonetogold();
          count=11;
        }
        if (count==11){
          gold();
        }
        if (count==12){
          goldtodiamond();
          count=13;
        }
        if (count==13){
          diamond();
        }
    delay(200);
}


//  Preset Colours
void blacktodiamond(){
    for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 2) {
    // sets the value (range from 0 to 255):
    r=r+2;
    if(r>=255){r=255;}
    g=g+2;
    if(g>=200){g=200;}
    b=b+2;
    if(b>=255){b=255;}
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}

// Blue/White Diamond
void diamond(){
  r=255; g=200; b=255;
  analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
}

void diamondtoiron(){
    for (int fadeValue = 0 ; fadeValue <= 254; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    b=b-3;
    if(b<=100){b=100;}
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}   

// White Iron
void iron(){
  r=255; g=200; b=100;
  analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
}
void irontoemerald(){
    for (int fadeValue = 0 ; fadeValue <= 254; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    r=r-5;
    g=g+5; if(g>=255){g=255;}
    b=b-5; if(b<=0){b=0;}
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}   
// Green Emerald
void emerald(){
  r=0; g=255; b=0;
  analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
}
void emeraldtolapis(){
    for (int fadeValue = 0 ; fadeValue <= 254; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    g=g-5;
    b=b+5;
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}
//  Blue Lapis
void lapis(){
  r=0; g=0; b=255;
  analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
}
void lapistoredstone(){
    for (int fadeValue = 0 ; fadeValue <= 254; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    r=r+5;
    b=b-5;
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}

//  Red Redstone
void redstone(){
  r=255; g=0; b=0;
  analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
}
void redstonetogold(){
    for (int fadeValue = 0 ; fadeValue <= 100; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    g=g+5;
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}

// Yellow Gold
void gold(){
  r=255; g=100; b=0;
  analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
}

void goldtodiamond(){
    for (int fadeValue = 0 ; fadeValue <= 254; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    g=g+3;
    if(g>=200){g=200;}
    b=b+5;
    if(b>=255){b=255;}
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}


void fadetoblack(){
    for (int fadeValue = 0 ; fadeValue <= 254; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    r=r-5;
    g=g-5;
    b=b-5;
    analogWrite(9, r); analogWrite(10, g); analogWrite(11, b);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    }
}

Credits

Cathprotech
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.