Sunteți pe pagina 1din 19

int blue = 9; // Define Digital Pins for each colour of the LED

int green = 10;


int red = 11;

int redPot = A0;


int greenPot = A1; //Define Analog Pins for the 3 potentiometers
int bluePot = A2;

int greenVal = 0; //Create a variable to store the state of each


Potentiometer
int blueVal = 0;
int redVal = 0;

const int BUTTON = 7; //Define the button Pin


int state = 0; //Create a variable to store wether button is on or off
int val = 0; //Create a variable to store the momentary state of the
button
int old_val = 0; //create a variable to store the previous state of the
button

void setup() {
// put your setup code here, to run once:

pinMode(green, OUTPUT); //Set LED's as output's, button as input


pinMode(blue, OUTPUT);
pinMode(red, OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.begin(9600); //Open the serial monitor at 9600
baud

val = digitalRead(BUTTON); // Check state of button

if ((val == HIGH) && (old_val == LOW)) { //Check to see if state of button


has changed
state = 1 - state; //Set the button as either on (1)
or off (0)
delay(10);
}

old_val = val; // Save the previous button


reading to compare next time through loop

greenVal = analogRead(greenPot); //Read the position of the


potentiometers
blueVal = analogRead(bluePot);
redVal = analogRead(redPot);

if (state == 1) { //If button is on, set the state


of each LED according to position
analogWrite(green, greenVal / 4); //of its correspoding
potentiometer. Anolog inputs range from 0-1023,
analogWrite(blue, blueVal / 4); // while anolog outputs as PMW
can be from 0-255. Therefore we must
analogWrite(red, redVal / 4); // divide the potentiometer
readings by 4 to set the state correctly

Serial.print("RGB(");
Serial.print(redVal/4);
Serial.print(",");
Serial.print(greenVal/4);
Serial.print(",");
Serial.print(blueVal/4); //Print the RGB Code, resuable
in any RGB application
Serial.println(")");

delay(50);
} else { // If button is off, set all
LED's to LOW/off
analogWrite(green, 0);
analogWrite(blue, 0);
analogWrite(red, 0);
delay(50);
}
}

//This code represent the easiest animation for LED CUBE

int temp = 50, cont = 0;

//This function loads all the cube


void load_all(void) {
//layer 1
digitalWrite(A2, LOW);
digitalWrite(A1, LOW);
digitalWrite(A0, LOW);
delay(1);

//layer 2
digitalWrite(A2, HIGH);
digitalWrite(A1, LOW);
digitalWrite(A0, LOW);
delay(1);

//layer 3
digitalWrite(A2, LOW);
digitalWrite(A1, HIGH);
digitalWrite(A0, LOW);
delay(1);

//layer 4
digitalWrite(A2, HIGH);
digitalWrite(A1, HIGH);
digitalWrite(A0, LOW);
delay(1);

//layer 5
digitalWrite(A2, LOW);
digitalWrite(A1, LOW);
digitalWrite(A0, HIGH);
delay(1);

//layer 6
digitalWrite(A2, HIGH);
digitalWrite(A1, LOW);
digitalWrite(A0, HIGH);
delay(1);

//layer 7
digitalWrite(A2, LOW);
digitalWrite(A1, HIGH);
digitalWrite(A0, HIGH);
delay(1);

//layer 8
digitalWrite(A2, HIGH);
digitalWrite(A1, HIGH);
digitalWrite(A0, HIGH);
delay(1);

//This function actives each layer one time and you can decide the time that
the layer turns on
void scrolling(int t) {
PORTB = 0x00;
digitalWrite(7, HIGH);
delay(t);
digitalWrite(7, LOW);

digitalWrite(8, HIGH);
delay(t);
digitalWrite(8, LOW);

digitalWrite(9, HIGH);
delay(t);
digitalWrite(9, LOW);

digitalWrite(10, HIGH);
delay(t);
digitalWrite(10, LOW);

digitalWrite(11, HIGH);
delay(t);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
delay(t);
digitalWrite(12, LOW);

digitalWrite(13, HIGH);
delay(t);
digitalWrite(13, LOW);

//This animation turns on one layer per time, and it increases the speed of
it, so finally you see all cube switched on
void one(void) {
PORTD = 0xff;
load_all();
while (1) {
scrolling(temp);

temp = temp - 2;

if (temp <= 0) {
temp = 1;
cont++;
if (cont == 1000) {
cont = 0;
temp = 100;
}
}

}
}

void setup() {
DDRD = 0xff;
DDRB = 0xff;
DDRC = 0xff;

void loop() {
one();
}
/*Led cube 4x4x4
code version 5
Arduino team Politehnika
*/
int niz[]={2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3};
int nizK[]={2,3,4,5,9,13,A3,A2,A1,A0,10,6};
int nizP[]={7,8,12,11};
int niz1[]={2,3,4,5,7,8};
int niz2[]={2,6,10,A0,7,11};
int niz3[]={A0,A1,A2,A3,11,12};
int niz4[]={5,9,13,A3,8,12};
int nizRES[]={5,4,9,3,8,13,2,7,12,A3,6,11,A2,10,A1,A0};
int niz5[]={2,6,3,7};
int niz6[]={4,8,5,9};
int niz7[]={10,A0,11,A1};
int niz8[]={12,A2,13,A3};
int niz9[]={2,6,10,3,4,8,12,11};
int niz10[]={2,7,12,11,8};
int niz11[]={2,7,12,A3,A2,13};
int niz12[]={2,3,4,5,6,10,A0};
int niz13[]={6,7,8,9,3,11,A1};
int niz14[]={10,11,12,13,4,8,A2};
int niz15[]={A0,A1,A2,A3,5,9,13};
int niz16[]={3,2,6,7,11,10,A0,A1,A2,A3,13,12,8,9,5,4};
int niz17[]={2,7,12,8,3,4,5,9,13,A3,A2,A1,11,6,10,A0};
int niz18[]={2,3,4,5,6,10,A0};
int niz19[]={2,3,4,5,7,11,A1};
int niz20[]={2,3,4,5,8,12,A2};
int niz21[]={2,3,4,5,9,13,A3};
int niz22[]={2,6,10,A0,7,8,9};
int niz23[]={2,6,10,A0,11,12,13};
int niz24[]={2,6,10,A0,A1,A2,A3};

void setup(){
for(int i=0;i<64;i++)pinMode(niz[i],OUTPUT);
}

void loop(){
sve();
odozgo();
levo();
krug();
zmija();
d1();
trapez();
RG();
resetka();
RG();
slucajno();
kockice();
kocka();
strela();
skener();
zmija2();
zmija3();
}
void sve(){
for(int j=0;j<64;j++)
{
digitalWrite(niz[j],HIGH);
delay(100);
digitalWrite(niz[j],LOW);
}
for(int j=0;j<64;j++){
digitalWrite(niz[j],HIGH);
}
delay(500);
for(int j=0;j<64;j++){
digitalWrite(niz[j],LOW);
}
}
void odozgo(){
int k=0;
while(k<8){
for(int j=k;j<64;j+=8){
digitalWrite(niz[j],HIGH);
}
delay(300);
for(int j=k;j<64;j+=8){
digitalWrite(niz[j],LOW);
}
k++;
}

}
void levo(){
int k=8,p=0;
while(p<8){
for(int j=k-8;j<k;j++){
digitalWrite(niz[j],HIGH);
}
delay(300);
for(int j=k-8;j<k;j++){
digitalWrite(niz[j],LOW);
}
k+=4;p++;
}
}
void krug(){
int k=0;
while(k<8){
for(int j=0;j<24;j++)
{
digitalWrite(nizK[j],HIGH);
digitalWrite(nizK[j+12],HIGH);
delay(100);
digitalWrite(nizK[j],LOW);
digitalWrite(nizK[j+12],LOW);
}
k++;
}
}
void zmija(){
for(int j=0;j<24;j++)
{
digitalWrite(nizK[j],HIGH);
delay(150);

}
for(int j=0;j<8;j++){
digitalWrite(nizP[j],HIGH);
delay(150);
}
for(int j=6;j>=0;j--){
digitalWrite(nizP[j],LOW);
delay(150);
}
for(int j=24;j>0;j--)
{
digitalWrite(nizK[j],LOW);
delay(150);

}
}
void RG (){
for(int j=0;j<16;j++){
digitalWrite(niz[j],HIGH);
}
delay(1000);
for(int j=0;j<16;j++){
digitalWrite(niz[j],LOW);
}

}
void d1(){
int k=0;
while(k<4){
for(int i=0;i<12;i++){
digitalWrite(nizK[i],HIGH);
}
delay(200);
for(int i=0;i<12;i++){
digitalWrite(nizK[i],LOW);
}
for(int i=0;i<4;i++){
digitalWrite(nizP[i],HIGH);
}
delay(200);
for(int i=0;i<4;i++){
digitalWrite(nizP[i],LOW);
}
k++;
}

}
void trapez(){
for(int i=0;i<6;i++){
digitalWrite(niz1[i],HIGH);
}
delay(500);
for(int i=0;i<6;i++){
digitalWrite(niz1[i],LOW);
}
for(int i=0;i<6;i++){
digitalWrite(niz2[i],HIGH);
}
delay(500);
for(int i=0;i<6;i++){
digitalWrite(niz2[i],LOW);
}
for(int i=0;i<6;i++){
digitalWrite(niz3[i],HIGH);
}
delay(500);
for(int i=0;i<6;i++){
digitalWrite(niz3[i],LOW);
}
for(int i=0;i<6;i++){
digitalWrite(niz4[i],HIGH);
}
delay(500);
for(int i=0;i<6;i++){
digitalWrite(niz4[i],LOW);
}
}
void resetka(){
int k=0;
while(k<16){
for(int i=0;i<16-k;i++){
digitalWrite(nizRES[i],HIGH);
}
delay(200);
for(int i=0;i<16-k;i++){
digitalWrite(nizRES[i],LOW);
}
k++;
}
}
void slucajno(){
int k=0,x;
while(k<20){
x=random(0,16);
digitalWrite(niz[x],HIGH);
delay(200);
digitalWrite(niz[x],LOW);
k++;
}

}
void kockice(){
for(int i=0; i<4; i++)
{
digitalWrite(niz6[i], HIGH);
}
delay(500);
for(int i=0; i<4; i++)
{
digitalWrite(niz6[i], LOW);
}
for(int i=0; i<4; i++)
{
digitalWrite(niz8[i], HIGH);
}
delay(500);
for(int i=0; i<4; i++)
{
digitalWrite(niz8[i], LOW);
}
for(int i=0; i<4; i++)
{
digitalWrite(niz5[i], HIGH);
}
delay(500);
for(int i=0; i<4; i++)
{
digitalWrite(niz5[i], LOW);
}
for(int i=0; i<4; i++)
{
digitalWrite(niz7[i], HIGH);
}
delay(500);
for(int i=0; i<4; i++)
{
digitalWrite(niz7[i], LOW);
}
}

void kocka(){

for(int i=0; i<4; i++)


{
digitalWrite(niz5[i], HIGH);
}
delay(500);
for(int i=0; i<4; i++)
{
digitalWrite(niz5[i], LOW);
}
for(int i=0; i<8; i++)
{
digitalWrite(niz9[i], HIGH);
}
delay(500);
for(int i=0; i<8; i++)
{
digitalWrite(niz9[i], LOW);
}
for(int i=0; i<12; i++)
{
digitalWrite(nizK[i], HIGH);
}
delay(500);
for(int i=0; i<12; i++)
{
digitalWrite(nizK[i], LOW);
}
}

void strela(){

for(int i=0; i<4; i++)


{
digitalWrite(niz5[i], HIGH);
}
delay(500);
for(int i=0; i<4; i++)
{
digitalWrite(niz5[i], LOW);
}
for(int i=0; i<5; i++)
{
digitalWrite(niz10[i], HIGH);
}
delay(500);
for(int i=0; i<5; i++)
{
digitalWrite(niz10[i], LOW);
}
for(int i=0; i<6; i++)
{
digitalWrite(niz11[i], HIGH);
}
delay(500);
for(int i=0; i<6; i++)
{

digitalWrite(niz11[i], LOW);

}
delay(50);
}

void skener(){
for(int i=0; i<7; i++)
{
digitalWrite(niz18[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz18[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz19[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz19[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz20[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz20[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz21[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz21[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz18[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz18[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz22[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz22[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz23[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz23[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz24[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz24[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz12[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz12[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz13[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz13[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz14[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz14[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz15[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz15[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz12[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz12[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz13[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz13[i], LOW);
}

for(int i=0; i<7; i++)


{
digitalWrite(niz14[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz14[i], LOW);
}
for(int i=0; i<7; i++)
{
digitalWrite(niz15[i], HIGH);
}
delay(500);
for(int i=0; i<7; i++)
{
digitalWrite(niz15[i], LOW);
}
}
void zmija2(){
for(int i=0; i<16; i++)
{
digitalWrite(niz16[i], HIGH);
delay(100);
}
for(int i=0; i<16; i++)
{
digitalWrite(niz16[i], LOW);
}
}
void zmija3(){
for(int i=0; i<16; i++)
{
digitalWrite(niz17[i], HIGH);
delay(100);
}
for(int i=0; i<16; i++)
{
digitalWrite(niz17[i], LOW);
}
}
/*

This code uses 1Sheeld and an arduino Uno board to control a 4x4x4 LED matrix using

the microphone of your smart phone.

The circuit:

* 64 LEDs form a 4x4x4 cube connected with the 1Sheeld and arduino board

* The coloumns control pins are connected to digital pins 0 to 13 and analogue pins

A4 and A5

* The layers control pins are connected to analouge pins A0 to A3.

by Hassan Ibrahim

*/

#define CUSTOM_SETTINGS

#define INCLUDE_PUSH_BUTTON_SHIELD

#define INCLUDE_MIC_SHIELD

/* Include 1Sheeld library. */

#include <OneSheeld.h>

// Define the pin connections of the LED matrix (columns and layer).

// Refer to the tutorial for more illustration.

int coloumn13 = 13; // coloumn13 means the coloumn connected to pin 13 on the arduino board

int coloumn12 = 12;


int coloumn11 = 11;

int coloumn10 = 10;

int coloumn9 = 9;

int coloumn8 = 8;

int coloumn7 = 7;

int coloumn6 = 6;

int coloumn5 = 5;

int coloumn4 = 4;

int coloumn3 = 3;

int coloumn2 = 2;

int coloumn1 = 1;

int coloumn0 = 0;

int coloumnA4 = A4;

int coloumnA5 = A5;

int layerA0 = A0; // layerA0 means the layer connected to analogue pin A0 on the arduino (The lowest
layer in this example)

int layerA1 = A1; // * The names are chosen this way in order to ease modification

int layerA2 = A2;

int layerA3 = A3;

int counter; // used to make variations in the coloumns

// the setup routine runs once when you press reset:

void setup() {

// Start communication.

OneSheeld.begin();

Serial.begin(115200);

// initialize each pin as an output.


pinMode(coloumn0, OUTPUT);

pinMode(coloumn1, OUTPUT);

pinMode(coloumn2, OUTPUT);

pinMode(coloumn3, OUTPUT);

pinMode(coloumn4, OUTPUT);

pinMode(coloumn5, OUTPUT);

pinMode(coloumn6, OUTPUT);

pinMode(coloumn7, OUTPUT);

pinMode(coloumn8, OUTPUT);

pinMode(coloumn9, OUTPUT);

pinMode(coloumn10, OUTPUT);

pinMode(coloumn11, OUTPUT);

pinMode(coloumn12, OUTPUT);

pinMode(coloumn13, OUTPUT);

pinMode(coloumnA4, OUTPUT);

pinMode(coloumnA5, OUTPUT);

pinMode(layerA0, OUTPUT);

pinMode(layerA1, OUTPUT);

pinMode(layerA2, OUTPUT);

pinMode(layerA3, OUTPUT);

} // end of setup

// the loop routine runs over and over again forever:

void loop() {

// all coloumns are connected to 5v (high).

digitalWrite(coloumn0,HIGH);
digitalWrite(coloumn1,HIGH);

digitalWrite(coloumn2,HIGH);

digitalWrite(coloumn3,HIGH);

digitalWrite(coloumn4,HIGH);

digitalWrite(coloumn5,HIGH);

digitalWrite(coloumn6,HIGH);

digitalWrite(coloumn7,HIGH);

digitalWrite(coloumn8,HIGH);

digitalWrite(coloumn9,HIGH);

digitalWrite(coloumn10,HIGH);

digitalWrite(coloumn11,HIGH);

digitalWrite(coloumn12,HIGH);

digitalWrite(coloumn13,HIGH);

digitalWrite(coloumnA4,HIGH);

digitalWrite(coloumnA5,HIGH);

delay(30);

// Get the noise level from the mic and control which layers to be connected to 0v (low).

// Each if-else block controls one layer.

// The values should be calibrated according to your mobile phone.

/*

To calibrate, play any sort of music near your smart phone and watch the readings of the Mic
shield and choose appropriate values.

*/

// In this example, steps of 6 give good results

if( Mic.getValue() > 70 ) // first layer control

{
digitalWrite(layerA0, LOW);

delay(50); // To make the display clearer. It could be modified to make if faster or


slower.

else

digitalWrite(layerA0, HIGH);

if( Mic.getValue() > 76 ) // second layer control

digitalWrite(layerA1, LOW);

delay(50);

else

digitalWrite(layerA1, HIGH);

if( Mic.getValue() > 82 ) // third layer control

digitalWrite(layerA2, LOW);

delay(50);

else

digitalWrite(layerA2, HIGH);

}
if( Mic.getValue() > 88 ) // fourth layer control

digitalWrite(layerA3, LOW);

delay(50);

else

digitalWrite(layerA3, HIGH);

} // end of loop