SoundTouch 🔊 Nerf 🔫 Target 🎯
Create your own Nerf target! If you don't like the music played on the SoundTouch, just hit the target! 🎯
Components and supplies
1
LED (generic)
1
Arduino Yun
1
Fast Vibration Sensor Switch
Apps and platforms
1
Arduino IDE
Project description
Code
soundtouch-nerf-target.ino
arduino
1/* 2 * Soundtouch Nerf Next target !!! 3 * https://github.com/T3kstiil3/soundtouch-nerf-target 4 * Aurélien Loyer :D 5 */ 6 7#include <Bridge.h> 8#include <Console.h> 9#include <HttpClient.h> 10#include <YunServer.h> 11#include <YunClient.h> 12 13YunServer server; 14 15const int statusLED = 13; 16const int switchTilt = 2; 17int val = 0; 18 19const int port = 8090; 20// edit with your soundtouch ip 21const String soundtouchIP = "10.0.10.166"; 22const String url = "http://" + soundtouchIP + ":8090/key"; 23const String data = "<?xml version='1.0' encoding='UTF-8' ?><key state='release' sender='Gabbo'>NEXT_TRACK</key>"; 24const String curlcommand = "curl -H 'Content-Type: application/xml' -X POST -d \\"<?xml version='1.0' encoding='UTF-8' ?><key state='press' sender='Gabbo'>NEXT_TRACK</key>\\" http://" + soundtouchIP + ":8090/key"; 25 26void setup() { 27 Serial.begin(9600); 28 29 pinMode (statusLED,OUTPUT); 30 pinMode (switchTilt,INPUT); 31 32 Bridge.begin(); 33 server.listenOnLocalhost(); 34 server.begin(); 35} 36 37void loop() 38{ 39 40 YunClient client = server.accept(); 41 42 val = digitalRead(switchTilt); 43 if (val == HIGH){ 44 digitalWrite(statusLED,HIGH); 45 nextTrack(); 46 delay(30000); // 30 secondes avant le prochain changement ! 47 } 48 else { 49 digitalWrite(statusLED,LOW); 50 } 51 52 //Process Client Requests 53 if (client) { 54 process(client); 55 client.stop(); 56 } 57 58 delay(15); 59} 60 61void nextTrack() { 62 Process p; 63 p.runShellCommand(curlcommand); 64} 65 66void process(YunClient client) { 67 String command = client.readStringUntil('\r'); 68} 69 70
soundtouch-nerf-target.ino
arduino
1/* 2 * Soundtouch Nerf Next target !!! 3 * https://github.com/T3kstiil3/soundtouch-nerf-target 4 5 * Aurélien Loyer :D 6 */ 7 8#include <Bridge.h> 9#include <Console.h> 10#include 11 <HttpClient.h> 12#include <YunServer.h> 13#include <YunClient.h> 14 15YunServer 16 server; 17 18const int statusLED = 13; 19const int switchTilt = 2; 20int val 21 = 0; 22 23const int port = 8090; 24// edit with your soundtouch ip 25const 26 String soundtouchIP = "10.0.10.166"; 27const String url = "http://" + soundtouchIP 28 + ":8090/key"; 29const String data = "<?xml version='1.0' encoding='UTF-8' ?><key 30 state='release' sender='Gabbo'>NEXT_TRACK</key>"; 31const String curlcommand = 32 "curl -H 'Content-Type: application/xml' -X POST -d \\"<?xml version='1.0' encoding='UTF-8' 33 ?><key state='press' sender='Gabbo'>NEXT_TRACK</key>\\" http://" + soundtouchIP 34 + ":8090/key"; 35 36void setup() { 37 Serial.begin(9600); 38 39 pinMode 40 (statusLED,OUTPUT); 41 pinMode (switchTilt,INPUT); 42 43 Bridge.begin(); 44 45 server.listenOnLocalhost(); 46 server.begin(); 47} 48 49void loop() 50{ 51 52 53 YunClient client = server.accept(); 54 55 val = digitalRead(switchTilt); 56 57 if (val == HIGH){ 58 digitalWrite(statusLED,HIGH); 59 nextTrack(); 60 61 delay(30000); // 30 secondes avant le prochain changement ! 62 } 63 else 64 { 65 digitalWrite(statusLED,LOW); 66 } 67 68 //Process Client Requests 69 70 if (client) { 71 process(client); 72 client.stop(); 73 } 74 75 delay(15); 76} 77 78void 79 nextTrack() { 80 Process p; 81 p.runShellCommand(curlcommand); 82} 83 84void 85 process(YunClient client) { 86 String command = client.readStringUntil('\ '); 87} 88 89
Downloadable files
schematics_laecZG2v8v.png
schematics_laecZG2v8v.png

Comments
Only logged in users can leave comments