CST-211 MiniProject Group 13
CST-211 MiniProject Group 13
CST-211 MiniProject Group 13
1
CST-211 Microcontroller Applications
2
CST-211 Microcontroller Applications
Miniproject 2: Motor
3
CST-211 Microcontroller Applications
4
CST-211 Microcontroller Applications
}
void speedUpandDown() {
int speed; int delayTime = 20; // milliseconds between each speed step // accelerate the motor
for(speed = 0; speed <= 255; speed++) {
analogWrite(motorPin,speed); // set the new speed
delay(delayTime); // delay between speed steps
} // decelerate the motor
for(speed = 255; speed >= 0; speed--) {
analogWrite(motorPin,speed); // set the new speed
delay(delayTime); // delay between speed steps
}
}
void serialSpeed() {
int speed;
Serial.println("Type a speed (0-255) into the box above,");
Serial.println("then click [send] or press [return]");
Serial.println();
while (Serial.available() > 0) {
speed = Serial.parseInt();
speed = constrain(speed, 0, 255);
Serial.print("Setting speed to "); // feedback and prints out the speed that you entered.
Serial.println(speed);
analogWrite(motorPin, speed); // sets the speed of the motor.
}
}
}
5
CST-211 Microcontroller Applications
6
CST-211 Microcontroller Applications
LCD
#include < LiquidCrystal.h>
int seconds = 0;
lcd_1(12, 11, 5, 4, 3, 2);
void setup() {
lcd_1.begin(16, 2);
lcd_1.print("hello world!");
}
void loop() {
lcd_1.setCursor(0, 1); // print the number of seconds since reset: lcd_1.print(seconds);
delay(1000); // Wait for 1000 millisecond(s)
seconds += 1;
}
UltraSonic Sensor
int echoPin = 12;
long duration, cm, inches;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT); //Define inputs and outputs
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
}