Sie sind auf Seite 1von 10

DAFT PUNK HELMET -

(https://www.youtube.com/c/ELECTRONOOBS)
(https://www.instagram.com/ELECTRONOOBS)
(https://www.facebook.com/Electronoobs)
(https://twitter.com/ELECTRONOOBS) ADVERTISERS

Daft Punk
helmet
CODE
H… Help me by sharing this post
Share 31

This is the code used with my Daft Punk helmet project. Make sure the BT mdoule is
not connected to the Tx and Rx pins and then compile and upload the code. you will
also need some libraries that you cold find below. Download those and install them
before you compile the code.
(http://bit.ly/2JAAfV

Download Daft Punk code: (last update 21/12/2018)


(images/Arduino/tut_62/Daft_Punk_BT_Helmet.zip) Envío G... Envío

Download Adafruit_GFX library: (eng_arduino_Adafruit_GFX.php)


Envío

Download Adafruit_NeoMatrix library:


(eng_arduino_Adafruit_NeoMatrix.php)
Envío… Envío… Envío
Download Adafruit_NeoPixel library:
$ 549.…
(eng_arduino_Adafruit_NeoPixel.php)

Best NYC Tennis

Club Membership $ 139

Included
TCR The Club of Riverdale $ 537.000 $ 119

$ 599.000 $ 90.000 $ 95.999 $ 69.

(eng_arduino_tut62_2.php)
/* Daft punk helmet code with Bluetooth control and microphone
* Tutorial webpage: https://www.electronoobs.com/eng_arduino_tut62.php
* Schematic: https://www.electronoobs.com/eng_arduino_tut62_sch1.php
* Part list: https://www.electronoobs.com/eng_arduino_tut62_parts1.php
*/

#include <Adafruit_GFX.h> //Downlaod: https://www.electronoobs.com/eng_arduino_Adafruit_GFX.php


#include <Adafruit_NeoMatrix.h> //Downlaod: https://www.electronoobs.com/eng_arduino_Adafruit_NeoMatrix.
php
#include <Adafruit_NeoPixel.h> //Downlaod: https://www.electronoobs.com/eng_arduino_Adafruit_NeoPixel.p
hp
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif

//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////EDITABLE VARIABLES///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
#define PIN 9 //Select here the digital pin used for the LED strip data pin
#define NUMPIXELS 105 //Amount of LEDs. I have 7 row of 15 LEDs wit a total of 105 LEDs

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(


15, //Select LEDs of each row (15 in my case)
7, //Select amount of rows (7 in my case)
PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT + //Define first data pin (right bottom corner is my fi
rst pin)
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, //Define the type of connection (in a zig zag connect
ions and divided by rows not columns)
NEO_GRB + NEO_KHZ800);

String text = "ELECTRONOOBS SUBSCRIBE"; //Put here the default text to be printed on the
LED matrix when it's powered on
int Delay = 5000; //Delay for the eye movement
int brightness = 10; //Defaulst brightness
int min_adc = 690; //min range of the microphone ADC read
int max_adc = 840; //max range of the microphone ADC read
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

/* * I defien 2 matrices because I've used two different code exampels to create my scroll text, eyes, e
tc..
That's why below I define a NeoPixel matrix and a simple matrix controlled LED by LED, one by one.
matrix 1 is "pixels" and matrix 2 is called "matrix"
*/

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };

//More variables
int string_length = 0;
static byte byteRead=0;
bool print_text = true;
bool print_eyes= false;
bool print_rainbow = false;
bool print_side_to_side = false;
bool print_spectrum = false;
bool print_Chase = false;
bool print_off = false;
unsigned long previousMillis = 0;

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////ADC config//////////////////////////////////////////////////
//ADC sampling variables
int adc_in = A0;
int adc = 0;
#define ADC_MULTISAMPLING 2
#define ADC_MULTISAMPLING_SAMPLES (1 << ADC_MULTISAMPLING)
//////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {
pinMode(adc_in,INPUT);
Serial.begin(9600); //Start the serial communication for the BT module

matrix.begin(); //Start the LED matrix 1


matrix.setTextWrap(false);
matrix.setBrightness(20);
pixels.setBrightness(20);
matrix.setTextColor(colors[0]);

pixels.begin(); // This initializes the NeoPixel library. //Start the LED matrix 2
}
int x = matrix.width();
int pass = 0;

void loop()
{
if(Serial.available()>0)
{
byteRead = Serial.read(); //Read data from the BT module
if(byteRead=='T') //If we receive a "T", then we gen into text scroll mode
{
text = Serial.readString(); //Store the bluetooth received text
print_text = true;
print_eyes= false;
print_rainbow = false;
print_side_to_side = false;
print_spectrum = false;
print_Chase = false;
print_off = false;
}
if(byteRead=='E') //If we receive a "E", then we gen into eyes mode
{
print_eyes= true;
print_text = false;
print_rainbow = false;
print_side_to_side = false;
print_spectrum = false;
print_Chase = false;
print_off = false;
}
if(byteRead=='B') //If we receive a "V", then we change brightness to the received val
ue
{
String Received = Serial.readString();
int brightness = (int(Received[0])-48)*10;
if(brightness == 0)
{
brightness = 100;
}
brightness = constrain(brightness,0,100);
matrix.setBrightness(brightness);
pixels.setBrightness(brightness);
Serial.println(brightness);
} Alfawise U30
if(byteRead=='O') //If we receive a "O", then we turn off the LEDs 2.8 inch Touch
{ Screen DIY
print_eyes= false;
print_text = false; Desktop 3D
print_rainbow = false;
Printer - U30
print_side_to_side = false;
print_spectrum = false; EU Plug Black
print_Chase = false;
print_off = true;
only $$162.89
} (https://www.gearbe
if(byteRead=='R') //If we receive a "R", then we get into rainbow mode printers-3d-
{ printer-
print_eyes= false;
print_text = false; kits/pp_009954647
print_rainbow = true; lkid=39527337)
print_side_to_side = false;
print_spectrum = false;
print_Chase = false;
print_off = false;
}

if(byteRead=='S') //If we receive a "S", then we get into robocop mode


{
print_eyes= false;
print_text = false;
print_rainbow = false;
print_side_to_side = true;
print_spectrum = false;
print_Chase = false;
print_off = false;
}

if(byteRead=='P') //If we receive a "P", then we get audio power mode


(microphone control)
{
print_eyes= false;
print_text = false;
print_rainbow = false;
print_side_to_side = false;
print_spectrum = true;
print_Chase = false;
print_off = false;
}

if(byteRead=='C') //If we receive a "C", then we get into random mode


{
print_eyes= false;
print_text = false;
print_rainbow = false;
print_side_to_side = false;
print_spectrum = false;
print_Chase = true;
print_off = false;
}
}//end of serial read

if(print_text && !print_off)


{
string_length = text.length();
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(text);
if(--x < -(string_length*6)) {
x = matrix.width();
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(60);
}//End of print text

if(print_eyes && !print_off)


{
int y = -3;
int i = 0;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= Delay)
{
previousMillis += Delay;
while(y < 3)
{
while (i < 105)
{
pixels.setPixelColor(i, pixels.Color(0,0,0));
i = i + 1;
}
i=0;

pixels.setPixelColor(33+y, pixels.Color(255,0,0));
pixels.setPixelColor(34+y, pixels.Color(255,0,0));
pixels.setPixelColor(40+y, pixels.Color(255,0,0));
pixels.setPixelColor(41+y, pixels.Color(255,0,0));
pixels.setPixelColor(47-y, pixels.Color(255,0,0));
pixels.setPixelColor(48-y, pixels.Color(255,255,255));
pixels.setPixelColor(49-y, pixels.Color(255,255,255));
pixels.setPixelColor(50-y, pixels.Color(255,0,0));
pixels.setPixelColor(54-y, pixels.Color(255,0,0));
pixels.setPixelColor(55-y, pixels.Color(255,255,255));
pixels.setPixelColor(56-y, pixels.Color(255,255,255));
pixels.setPixelColor(57-y, pixels.Color(255,0,0));
pixels.setPixelColor(63+y, pixels.Color(255,0,0));
pixels.setPixelColor(64+y, pixels.Color(255,0,0));
pixels.setPixelColor(70+y, pixels.Color(255,0,0));
pixels.setPixelColor(71+y, pixels.Color(255,0,0));

pixels.show(); // This sends the updated pixel color to the hardware.


delay(150);
y = y + 1;
}
//delay(1000);
AFFILATE
y = 2;

while(y > -3)


{
while (i < 105)
{
pixels.setPixelColor(i, pixels.Color(0,0,0));
i = i + 1;
}
i=0;

pixels.setPixelColor(33+y, pixels.Color(255,0,0));
pixels.setPixelColor(34+y, pixels.Color(255,0,0));
pixels.setPixelColor(40+y, pixels.Color(255,0,0));
pixels.setPixelColor(41+y, pixels.Color(255,0,0));
pixels.setPixelColor(47-y, pixels.Color(255,0,0));
pixels.setPixelColor(48-y, pixels.Color(255,255,255));
pixels.setPixelColor(49-y, pixels.Color(255,255,255));
pixels.setPixelColor(50-y, pixels.Color(255,0,0));
pixels.setPixelColor(54-y, pixels.Color(255,0,0));
pixels.setPixelColor(55-y, pixels.Color(255,255,255));
pixels.setPixelColor(56-y, pixels.Color(255,255,255));
pixels.setPixelColor(57-y, pixels.Color(255,0,0));
pixels.setPixelColor(63+y, pixels.Color(255,0,0));
pixels.setPixelColor(64+y, pixels.Color(255,0,0));
pixels.setPixelColor(70+y, pixels.Color(255,0,0));
pixels.setPixelColor(71+y, pixels.Color(255,0,0));

pixels.show(); // This sends the updated pixel color to the hardware.


delay(150);
y = y - 1;
}

y = -2 ;
}//end of current millis
}//end of print eyes

if(print_rainbow && !print_off)


{
rainbow(1);
}

if(print_Chase && !print_off)


{
theaterChase(pixels.Color(127, 127, 127), 50);
}

if(print_side_to_side && !print_off)


{
int x = -3;
int i = 0;
int k = 0;
int Delay_time = 20;

while (k < 105)


{
pixels.setPixelColor(k, pixels.Color(0,0,0));
k = k + 1;
}
k=0;

while(i < 15)


{
pixels.setPixelColor(60-i, pixels.Color(0,0,0));
pixels.setPixelColor(59-i, pixels.Color(255,255,255));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(Delay_time);
i = i + 1;
}

i = 14;
delay(100);

while(i >= 0)
{
pixels.setPixelColor(58-i, pixels.Color(0,0,0));
pixels.setPixelColor(59-i, pixels.Color(255,255,255));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(Delay_time);
i = i - 1;
}

i = 0;
delay(100);

}//end of side to side

if(print_spectrum && !print_off)


{
int val = read_adc();
int level = map(val,min_adc,max_adc,1,7);
Serial.println(val); Creality3D CR
analogWrite(13,level); - 10S 3D
//delay(1);
Printer - EU
Plug Upgrade
if(level==1)
{ Version Coffee
int r = 0;
while (r < 105)
and Black only
{
pixels.setPixelColor(r, pixels.Color(0,0,0));
$$352.94
r = r + 1;
} (https://www.gearbe
r=0;
while (r < 15)
printers-3d-
{ printer-
pixels.setPixelColor(r, pixels.Color(0,255,0));
r = r + 1; kits/pp_796481.htm
} lkid=39527111)
r=0;
pixels.show(); // This sends the updated pixel color to the hardware.
}//end of level 1

if(level==2)
{
int r = 0;
while (r < 105)
{
pixels.setPixelColor(r, pixels.Color(0,0,0)); Creality 3D
r = r + 1; Ender-3 V-slot
}
r=0; Prusa I3 DIY
while (r < 15) 3D Printer Kit
{
pixels.setPixelColor(r, pixels.Color(0,255,0)); 220 x 220 x
r = r + 1;
250mm
}
Printing Size -
while (r < 30)
{
EU Plug Black
pixels.setPixelColor(r, pixels.Color(150,255,0)); only $$153.84
r = r + 1;
} (https://www.gearbe
r=0; printers-3d-
pixels.show(); // This sends the updated pixel color to the hardware.
}//end of level 2 printer-
kits/pp_1845899.ht
if(level==3) lkid=39527206)
{
int r = 0;
while (r < 105)
{
pixels.setPixelColor(r, pixels.Color(0,0,0));
r = r + 1;
}
r=0;
while (r < 15)
{ Alfawise U20
pixels.setPixelColor(r, pixels.Color(0,255,0));
r = r + 1; Large Scale
}
2.8 inch Touch
while (r < 30) Screen DIY
{
pixels.setPixelColor(r, pixels.Color(150,255,0));
3D Printer -
r = r + 1; EU - U20 EU
}
Plug Black
while (r < 45) only $$253.39
{
pixels.setPixelColor(r, pixels.Color(255,255,0)); (https://www.gearbe
r = r + 1; printers-3d-
}
r=0; printer-
pixels.show(); // This sends the updated pixel color to the hardware.
kits/pp_1841229.ht
}//end of level 3
lkid=39527285)
if(level==4)
{
int r = 0;
while (r < 105)
{
pixels.setPixelColor(r, pixels.Color(0,0,0));
r = r + 1;
}
r=0;
while (r < 15)
{
pixels.setPixelColor(r, pixels.Color(0,255,0));
r = r + 1;
}

while (r < 30)


{
pixels.setPixelColor(r, pixels.Color(150,255,0));
r = r + 1; Airtable, a…
} Ad Airtable

diagram.js
while (r < 45) Ad mindfusion.eu
{ Adafruit…
pixels.setPixelColor(r, pixels.Color(255,255,0)); electronoobs.com
r = r + 1;
Best…
}
Ad NAGI HAIR

while (r < 60) Arduino…


electronoobs.com
{
pixels.setPixelColor(r, pixels.Color(255,150,0)); Slider arduino…
r = r + 1; electronoobs.com
} Voice menu…
electronoobs.com

PWM receiver…
r=0;
electronoobs.com
pixels.show(); // This sends the updated pixel color to the hardware.
}//end of level 4 Analog POV…
electronoobs.com

How to make…
if(level==5) electronoobs.com
{ LCD special…
int r = 0; electronoobs.com
while (r < 105)
i2c 16x2 LCD…
{
electronoobs.com
pixels.setPixelColor(r, pixels.Color(0,0,0));
r = r + 1; 16x2 LCD…
electronoobs.com
}
r=0;
while (r < 15)
{
pixels.setPixelColor(r, pixels.Color(0,255,0));
r = r + 1;
}

while (r < 30)


{
pixels.setPixelColor(r, pixels.Color(150,255,0));
r = r + 1;
}

while (r < 45)


{
pixels.setPixelColor(r, pixels.Color(255,255,0));
r = r + 1;
}

while (r < 60)


{
pixels.setPixelColor(r, pixels.Color(255,150,0));
r = r + 1;
}

while (r < 75)


{
pixels.setPixelColor(r, pixels.Color(255,75,0));
r = r + 1;
}

r=0;
pixels.show(); // This sends the updated pixel color to the hardware.
}//end of level 5

if(level==6)
{
int r = 0;
while (r < 105)
{
pixels.setPixelColor(r, pixels.Color(0,0,0));
r = r + 1;
}
r=0;
while (r < 15)
{
pixels.setPixelColor(r, pixels.Color(0,255,0));
r = r + 1;
}

while (r < 30)


{
pixels.setPixelColor(r, pixels.Color(150,255,0));
r = r + 1;
}
while (r < 45)
{
pixels.setPixelColor(r, pixels.Color(255,255,0));
r = r + 1;
}

while (r < 60)


{
pixels.setPixelColor(r, pixels.Color(255,150,0));
r = r + 1;
}

while (r < 75)


{
pixels.setPixelColor(r, pixels.Color(255,50,0));
r = r + 1;
}

while (r < 90)


{
pixels.setPixelColor(r, pixels.Color(255,25,0));
r = r + 1;
}

r=0;
pixels.show(); // This sends the updated pixel color to the hardware.
}//end of level 6

if(level==7)
{
int r = 0;
while (r < 105)
{
pixels.setPixelColor(r, pixels.Color(0,0,0));
r = r + 1;
}
r=0;
while (r < 15)
{
pixels.setPixelColor(r, pixels.Color(0,255,0));
r = r + 1;
}

while (r < 30)


{
pixels.setPixelColor(r, pixels.Color(150,255,0));
r = r + 1;
}

while (r < 45)


{
pixels.setPixelColor(r, pixels.Color(255,255,0));
r = r + 1;
}

while (r < 60)


{
pixels.setPixelColor(r, pixels.Color(255,150,0));
r = r + 1;
}

while (r < 75)


{
pixels.setPixelColor(r, pixels.Color(255,50,0));
r = r + 1;
}

while (r < 90)


{
pixels.setPixelColor(r, pixels.Color(255,25,0));
r = r + 1;
}

while (r < 105)


{
pixels.setPixelColor(r, pixels.Color(255,0,0));
r = r + 1;
}

r=0;
pixels.show(); // This sends the updated pixel color to the hardware.
}//end of level 7
}//end of print spectrum
if(print_off)
{
int r = 0;
while (r < 105)
{
pixels.setPixelColor(r, pixels.Color(0,0,0));
r = r + 1;
}
pixels.show();
r=0;
}

}//end of void loop

void rainbow(uint8_t wait) {


uint16_t i, j;

for(j=0; j<256; j++) {


for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, Wheel((i+j) & 255));
}
pixels.show();
delay(wait);
}
}

uint32_t Wheel(byte WheelPos) {


WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

float read_adc()
{
// Filter the ADC by multisampling with the values defined at the beginning
adc = 0;
for (int i = 0; i < ADC_MULTISAMPLING_SAMPLES; ++i)
adc += analogRead(adc_in);
adc = adc >> ADC_MULTISAMPLING;

return(adc);
}

//Theatre-style crawling lights.


void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < pixels.numPixels(); i=i+3) {
pixels.setPixelColor(i+q, c); //turn every third pixel on
}
pixels.show();

delay(wait);

for (uint16_t i=0; i < pixels.numPixels(); i=i+3) {


pixels.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
1 Comment Sort by Newest

Add a comment...

Dario Martin
Hola...
consulta:
por qué si todo, según tengo entendido, funciona con 5V usas una LiPo de 11.1V?
En Argentina me costo consegir la tira de leds y no quiero quemarlos...
gracias...
Like · Reply · 29w

Jaspreet Singh Rooprai


The Arduino Nano can be powered via the Mini-B USB connection, 6-20V unregulated external power
supply (pin 30), or 5V regulated external power supply (pin 27)
Like · Reply · 1 · 21w

Facebook Comments Plugin

(eng_arduino_tut62_2.php)

ELECTRONOOBS 2019
Keep up you guys!

Das könnte Ihnen auch gefallen