Étape 2: Télécharger votre dessin !
Vous pouvez maintenant télécharger le croquis sur votre arduino et testez-le.
Ce code LYT adresse est 0,0 et PL1167 chip select est sur la broche 10 alors s’il vous plaît modifiez-les en conséquence à vos paramètres.
Le niveau sonore est continuellement acquis sur l’entrée A0 et les pics audio, tant positifs que négatifs, sont calculés en soustrayant la valeur center (340) à la valeur lue analogique et en appliquant la fonction (absolue) de l’ABS.
Si cette valeur dépasse le seuil SOUND_LEVEL une nouvelle couleurs aléatoires est envoyé à la LYT.
Cela va générer des variations de préférence sur les sons graves.
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * *<br> Code by AUTHOMETION S.r.l. Version: 1.00 Date: 02.06.2015 * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <SPI.h> #include <PL1167.h> #include <Lytwifi.h> #include <SoftwareSerial.h> #include <WiFiInterrupt.h> #define PL1167_CS_PIN 10 #define BULB_ADDRESS_HIGH 0 #define BULB_ADDRESS_LOW 0 #define SOUND_LEVEL 100
//ESP8266 Serial SoftwareSerial mySerial(5, 6); // RX, TX LYTWiFi myNetWork(mySerial);
void setup() { Serial.begin(115200, SERIAL_8N1); myNetWork.vfInitialize(PL1167_CS_PIN); vfISRInit(&myNetWork); //Initialize random generator randomSeed(analogRead(0)); }
void loop() { int adc_sound; //POWER ON LYT myNetWork.ui8fSwitchOnAndCheck(BULB_ADDRESS_HIGH, BULB_ADDRESS_LOW, C_MULTICAST); delay(2000); while(1) { adc_sound=analogRead(0); //CONNECT MICROPHONE VCC TO ARDUINO 3.3 VDC FOR BETTER PERFORMANCE adc_sound=abs(adc_sound - 350);// Center on zero if(adc_sound>SOUND_LEVEL) { Serial.println(adc_sound); myNetWork.ui8fSetRGBValuesAndCheck(BULB_ADDRESS_HIGH, BULB_ADDRESS_LOW, random(255), random(255), random(255), C_MULTICAST); } } }