donderdag 10 mei 2012

Arduino code:
dit is de code die ik momenteel gebruik om de robot aan te sturen, de muziek die het robotje zal maken als hij water aanraakt moet nog gecodeerd worden.
de drawdio zal het signaal geven om de muziek code te starten en misschien ook op een bepaalde manier beinvloeden
/* initial pin declaration 
the value doesn't change during the loop but is used for name only */
int analogInPin = A0; 
int analogOutPin = 11;
int analogOutPin2 = 5;
int drawdiopin=A1;
int speakerpin=3;
int turnswitchrechts=2;
int turnswitchlinks=0;

/* initial value declaration
these are the values that change state or value in the program*/
int sensorValue = 0;      
int outputValue = 0; 
int buttonStatelinks = 0;
int buttonStaterechts = 0;
int thisPitch = 0;
void setup() {
 /* assigning pin modes*/
  Serial.begin(9600); 
  pinMode(turnswitchrechts,INPUT);
  pinMode(turnswitchlinks,INPUT);
    pinMode(analogOutPin,OUTPUT);
  pinMode(analogOutPin2,OUTPUT);
}

void loop() {
  /* side collision sensors*/
  buttonStatelinks = digitalRead(0);
  buttonStaterechts = digitalRead(2);
/*controlling the max speed with a potentiometer*/

  sensorValue = analogRead(analogInPin);            
  outputValue = map(sensorValue, 0, 1023, 0, 255 );  

  /* mapping out the drawdio to control the sound made from the speaker
  music control still needs to be made*/

   /* random path followed by the robot*/
analogWrite(analogOutPin, random(40,outputValue));           
analogWrite(analogOutPin2, random(40,outputValue));           
 delay(random(10,5000));

}
                      

Geen opmerkingen:

Een reactie posten