Difference between revisions of "Wiki groep 8"

From DigitalCraft_Wiki
Jump to navigation Jump to search
Line 48: Line 48:
 
   
 
   
 
  */
 
  */
int melody[] = {32,4699};
+
#include <Servo.h>
int sensorPin = A0;    // select the input pin for the potentiometer
+
 
int ledPin = 13;      // select the pin for the LED
+
int sensorAnalog = A0;    // select the input pin for the potentiometer
float sensorValue = 0;  // variable to store the value coming from the sensor
+
    // select the pin for the LED
int speakerPin = 8;
+
 
 +
int sensorDigital = 3;
 +
 
 +
int servo1Pin = 9;
 +
int servo2Pin  =10;
 +
 
 +
Servo servo1;  // create servo object to control a servo
 +
Servo servo2;
 +
 
 +
void moveServo(Servo servo,int stroke)
 +
{
 +
  int servoValue = servo.read();
 +
  if (servoValue == stroke){
 +
    servo.write(0);
 +
    Serial.println("servo to 0");
 +
  }else {
 +
    servo.write(stroke);
 +
    Serial.println("servo to 160");
 +
  }
 +
  Serial.println("moved servo");
 +
}
 +
 
 +
 
 +
 
 
void setup() {
 
void setup() {
 
   // declare the ledPin as an OUTPUT:
 
   // declare the ledPin as an OUTPUT:
   pinMode(ledPin, OUTPUT);
+
   pinMode(sensorDigital,INPUT);
 +
  pinMode(sensorAnalog,INPUT);
 
   Serial.begin(9600);
 
   Serial.begin(9600);
 +
  servo1.attach(servo1Pin);
 +
  servo2.attach(servo2Pin);
 +
  servo1.write(1);
 +
  servo2.write(1);
 
}
 
}
 +
 +
 +
 +
boolean hasMusic =false;
 +
int servoStroke =160;
 +
 +
  
 
void loop() {
 
void loop() {
 
   // read the value from the sensor:
 
   // read the value from the sensor:
  for (int thisNote =0; thisNote<2; thisNote++){
+
   
    tone(speakerPin,melody[thisNote],1000);
+
    hasMusic = digitalRead(sensorDigital);
     delay(200);
+
    Serial.print("has Music: ");
     sensorValue = analogRead(sensorPin);
+
    Serial.println(hasMusic);
 
+
    if (hasMusic){
     Serial.println(sensorValue);   
+
      moveServo(servo1,servoStroke);
 +
      moveServo(servo2,servoStroke);  
 +
    
 +
    Serial.print("Analog: ");
 +
     Serial.print(analogRead(sensorAnalog));
 +
    Serial.print( " Digital: ");
 +
     Serial.println(digitalRead(sensorDigital));   
 
   // turn the ledPin on
 
   // turn the ledPin on
 
+
   
 
     delay(1000);
 
     delay(1000);
     noTone(8);
+
      
  }  
+
   
 
}
 
}
 
</code>
 
</code>
  
 
==Eind Resultaat==
 
==Eind Resultaat==

Revision as of 15:59, 27 October 2014

Tools and tech wiki pagina van groep 8

Groepsleden

  • Bonny van der Sande
  • Shushanik Moutafian
  • Meleny Spits
  • Tran, twan


Inspiratie

Concept

Techniek

Montage

Hier kunnen foto's en een stukje tekst voor het monteren van de arduino op het autotje, het stukje solderen hoe dat gedaan is uitleggen

Sensoren

We hebben gebruik gemaakt van een [| Sound Detection Sensor Module] waarvan we in eerste instantie niet precies wisten of deze werkte. Door deze sensor welke bestaat uit een microfoon, een potmeter en een zowel een analoge als een digitale output, los aan te sluiten op de arduino met zowel de digitale als de analoge aansluiting konden we zien welke input er binnen kwam. Hierbij hebben we de volgende code gebruikt: /*

 Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED)  connected to digital pin 13. 
The amount of time the LED will be on and off depends on
the value obtained by analogRead(). 

The circuit:
* Potentiometer attached to analog input 0
* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V
* LED anode (long leg) attached to digital output 13
* LED cathode (short leg) attached to ground

* Note: because most Arduinos have a built-in LED attached 
to pin 13 on the board, the LED is optional.


Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe

This example code is in the public domain.

http://arduino.cc/en/Tutorial/AnalogInput

*/
#include <Servo.h> 

int sensorAnalog = A0; // select the input pin for the potentiometer

   // select the pin for the LED

int sensorDigital = 3;

int servo1Pin = 9; int servo2Pin =10;

Servo servo1; // create servo object to control a servo Servo servo2;

void moveServo(Servo servo,int stroke) {

  int servoValue = servo.read();
  if (servoValue == stroke){
   servo.write(0);
    Serial.println("servo to 0");
  }else { 
    servo.write(stroke); 
    Serial.println("servo to 160");
  }
 Serial.println("moved servo");
}


void setup() {

 // declare the ledPin as an OUTPUT:
 pinMode(sensorDigital,INPUT);
 pinMode(sensorAnalog,INPUT);
 Serial.begin(9600);
 servo1.attach(servo1Pin);
 servo2.attach(servo2Pin);
 servo1.write(1);
 servo2.write(1);

}


boolean hasMusic =false; int servoStroke =160;


void loop() {

 // read the value from the sensor:
   
   hasMusic = digitalRead(sensorDigital);
   Serial.print("has Music: ");
   Serial.println(hasMusic);
   if (hasMusic){
     moveServo(servo1,servoStroke); 
     moveServo(servo2,servoStroke); 
   }  
   Serial.print("Analog: ");
   Serial.print(analogRead(sensorAnalog));
   Serial.print( " Digital: ");
   Serial.println(digitalRead(sensorDigital));  
 // turn the ledPin on
   
   delay(1000);
   

}

Eind Resultaat