====== Fetit Filou ====== A la demande de Buz, création d'un petit filou géant, avec interaction. * détection de personne devant le Filou * faire bouger les yeux * faire de la lumière * lancer une interjection de Buz ====fabrication==== structure bois de recup format Filou en 3D Arduino détection par capteur ultrason SR04 2 servos ====Detection==== Module SR04 ultrason {{media_04:fetitfilou_sr04.jpg?nolink|}} facile et efficace ! librairie Ultrasonic d'Eric Simões arduino=>SR04 5V=>VCC GND=>GND D2=>Echo D3=>Trig ====Bruit==== utilisation d'un "DY Player" , une carte pour lecteur MP3 DIY . {{media_04:fetitfilou_dyplayer.jpg?nolink|}} module DY-SV5W carte avec lecteur microSD et ampli 5W intégré utilisation en Mode UART ( envoie de commande par le port TX/RX série de l'arduino)=> permet 255 sons facilement Sans prise de tête avec la librairie [[https://github.com/SnijderC/dyplayer|dyplayer de SnijderC]] juste 3 fils : arduino=>DFplayer 5V=>+5V GND=>-5V D1/TX=>IO1/RX ====Lumière=== juste une LED RGB ! arduino=>LED 5V=>V D4=>R D5=>B D6=>G ==== code ==== #include //son #include "DYPlayerArduino.h" DY::Player player; int son = 1; //detection SR04 #include Ultrasonic ultrasonic(2, 3); int distance; // yeux #include Servo eye1; Servo eye2; const byte EYE1PIN = 8; // broche servo Oeil const byte EYE2PIN = 9; // broche servo Oei1 byte eye1Pos = 0; byte eye2Pos = 0; //lumiere const byte COLOR[8] = {0b000, 0b100, 0b010, 0b001, 0b101, 0b011, 0b110, 0b111}; /* Broches */ const byte PIN_LED_R = 4; const byte PIN_LED_G = 5; const byte PIN_LED_B = 6; byte rvb = 0; void setup() { //Serial.begin(9600); player.begin(); player.setVolume(20); eye1.attach(EYE1PIN); eye2.attach(EYE2PIN); randomSeed(analogRead(0)); pinMode(PIN_LED_R, OUTPUT); pinMode(PIN_LED_G, OUTPUT); pinMode(PIN_LED_B, OUTPUT); displayColor(COLOR[7]); } void loop() { //lecture de la distance en CM distance = ultrasonic.read(); delay(500); if (distance < 50) { // couleur aleatoire //rvb=byte(random(0,7); displayColor(COLOR[int(random(0, 7))]); delay(10); //lecture d'un son aleatoire son = int(random(1, 9)); player.playSpecified(son); delay(250); displayColor(COLOR[int(random(0, 7))]); // servo position aleatoire eye1Pos = int(random(180)); eye2Pos = int(random(180)); eye1.write(eye1Pos); eye2.write(eye2Pos); delay(50); displayColor(COLOR[int(random(0, 7))]); //attente avant prochaine declanchement delay(4000); // remise a off displayColor(COLOR[7]); distance = 300;// forcage distance>50 } } /** Affiche une couleur */ void displayColor(byte color) { // Assigne l'état des broches // Version cathode commune //digitalWrite(PIN_LED_R, bitRead(color, 2)); //digitalWrite(PIN_LED_G, bitRead(color, 1)); //digitalWrite(PIN_LED_B, bitRead(color, 0)); // Version anode commune digitalWrite(PIN_LED_R, !bitRead(color, 2)); digitalWrite(PIN_LED_G, !bitRead(color, 1)); digitalWrite(PIN_LED_B, !bitRead(color, 0)); }