Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_SR_LCD3.h>
- const int PIN_LCD_STROBE = 2;
- const int PIN_LCD_DATA = 3;
- const int PIN_LCD_CLOCK = 4;
- LiquidCrystal_SR_LCD3 lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE);
- /* MOTOR */
- int mt1=5, mt2=6, mt3=12, mt4=8;
- #define enA NULL
- #define in1 8
- #define in2 6
- #define enB NULL
- #define in3 12
- #define in4 5
- int motorSpeedA = 0;
- int motorSpeedB = 0;
- /* BUTTON SW3 SW4 SW5 SW6*/
- int sw3=8, sw4=13, sw5=11, sw6=12;
- /* END BUTTON */
- void setup() {
- Serial.begin(9600);
- lcd.clear();
- pinMode(7, OUTPUT);
- /* BUTTON */
- //pinMode(sw3, INPUT);
- pinMode(sw4, INPUT);
- pinMode(sw5, INPUT);
- //pinMode(sw6, INPUT);
- /* END BUTTON */
- /* MOTOR */
- pinMode(enA, OUTPUT);
- pinMode(enB, OUTPUT);
- pinMode(in1, OUTPUT);
- pinMode(in2, OUTPUT);
- pinMode(in3, OUTPUT);
- pinMode(in4, OUTPUT);
- /* END MOTOR */
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- lcd.begin(16, 2);
- lcd.home();
- lcd.setCursor(4,0);
- lcd.print("*Welcome*"); delay(1000);
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print("Line Follower");
- lcd.setCursor(6,1);
- lcd.print("v1.0");
- delay(3000);
- lcd.clear();
- }
- int kecepatan = 100;
- void loop() {
- if(Serial.available()){
- digitalWrite(7, HIGH);
- char controllRobo = Serial.read();
- lcd.setCursor(0,0);
- lcd.print(controllRobo);
- if(controllRobo == '8'){
- fmotorpwm(kecepatan, kecepatan);
- Serial.println("Forward");
- }else if(controllRobo == '5'){
- smotor();
- Serial.println("STOP!");
- digitalWrite(7, LOW);
- }else if(controllRobo == '2'){
- bmotor();
- Serial.println("Back");
- digitalWrite(7, LOW);
- }else if(controllRobo == '4'){
- //Speed-
- if(kecepatan > 5 && kecepatan <= 255){
- kecepatan -= 5;
- }
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(kecepatan);
- Serial.println(kecepatan);
- }else if(controllRobo == '6'){
- //Speed+
- if(kecepatan >= 0 && kecepatan < 250){
- kecepatan += 5;
- }
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print(kecepatan);
- Serial.println(kecepatan);
- }
- }
- }
- void fmotor(){
- analogWrite(in2, 255);
- analogWrite(in4, 255);
- }
- void bmotor(){
- digitalWrite(in1, HIGH);
- digitalWrite(in3, HIGH);
- }
- void smotor(){
- digitalWrite(in1, LOW);
- digitalWrite(in3, LOW);
- analogWrite(in2, 0);
- analogWrite(in4, 0);
- }
- void fmotorpwm(int motora, int motorb){
- analogWrite(in2, motora);
- analogWrite(in4, motorb);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement