Difference between revisions of "Arduino 101"

From LVL1
Jump to navigation Jump to search
Line 1: Line 1:
 
= Project 1 =
 
= Project 1 =
<code>
+
{
 
int potInputPin = 0;
 
int potInputPin = 0;
 
int servoOutputPin = 11;
 
int servoOutputPin = 11;
Line 10: Line 10:
  
 
void setup()  
 
void setup()  
`{
+
{
 
   pinMode(servoOutputPin, OUTPUT);
 
   pinMode(servoOutputPin, OUTPUT);
 
   pinMode(smallAngleLEDPin, OUTPUT);
 
   pinMode(smallAngleLEDPin, OUTPUT);
Line 16: Line 16:
 
   analogWrite(servoOutputPin, analogValue);
 
   analogWrite(servoOutputPin, analogValue);
 
   Serial.begin(9600);
 
   Serial.begin(9600);
`}
+
}
  
 
void loop()  
 
void loop()  
Line 41: Line 41:
 
   delay(100);
 
   delay(100);
 
}
 
}
</code>
+
}

Revision as of 00:27, 7 November 2015

Project 1

{ int potInputPin = 0; int servoOutputPin = 11; int smallAngleLEDPin = 2; int largeAngleLEDPin = 4; int minValue = 64; int maxValue = 192; int analogValue = 512;

void setup() {

 pinMode(servoOutputPin, OUTPUT);
 pinMode(smallAngleLEDPin, OUTPUT);
 pinMode(largeAngleLEDPin, OUTPUT);
 analogWrite(servoOutputPin, analogValue);
 Serial.begin(9600);

}

void loop() {

 analogValue = analogRead(potInputPin);
 Serial.println(analogValue);
 analogValue = analogValue / 4;
 Serial.println(analogValue);
 if (analogValue < minValue)
 {
   digitalWrite(smallAngleLEDPin, HIGH);
 }
 else if (analogValue > maxValue)
 {
   digitalWrite(largeAngleLEDPin, HIGH);
 }
 else
 {
   digitalWrite(smallAngleLEDPin, LOW);
   digitalWrite(largeAngleLEDPin, LOW);
   analogWrite(servoOutputPin, analogValue);
 }  
 delay(100);

} }