Stock workshop Robotics and Modular Machines:: Difference between revisions
(Created page with "Robotics and Modular Machines learning process document photos... for optical instrument code: //no moter //sensor pin const int ldrPin = A1; //light pin const int ledPi...") |
No edit summary |
||
Line 50: | Line 50: | ||
Hardware: | Hardware: | ||
[[image:IMG 2901.JPG| 900px]] |
Revision as of 17:19, 6 March 2013
Robotics and Modular Machines
learning process
document photos...
for optical instrument
code:
//no moter //sensor pin const int ldrPin = A1;
//light pin const int ledPin = 13; //speaker pin const int speakerPin = 9;
void setup(){
Serial.begin(115200); // using those pins as output
pinMode(ledPin, OUTPUT); pinMode(speakerPin, OUTPUT);
}
void loop() {
int ldrVal = analogRead(ldrPin); //map the value of the light sensor ldrVal = map(ldrVal, 170, 600, 0, 1023); //constrain the vaule from 0 to 1023 ldrVal = constrain(ldrVal, 0, 1023);
// turning on the led
digitalWrite(ledPin, HIGH);
Serial.println(ldrVal);
makeTone(ldrVal);
}
void makeTone(int freq){
digitalWrite(speakerPin, HIGH); delayMicroseconds(freq); digitalWrite(speakerPin, LOW); delayMicroseconds(freq);
}
Hardware: