INPUT JUMLAH BLINK LED & DELAY SECARA SERIAL
PADA ARDUINO
Berikut Program nya :
const int led=13;
int bataskonter=0;
int bataskonter1=0;
String datamasuk;
String datamasuk1;
String datamasuk2;
int konter1=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led,OUTPUT);
Serial.println("<:masukkan jumlah nyala led:>");
}
void loop() {
if(Serial.available() > 0){
datamasuk=Serial.readStringUntil('\n');
bataskonter=datamasuk.toInt();
Serial.print("Blink Led =");
Serial.print(bataskonter);
Serial.println("kali");
Serial.println("<:masukkan nilai delay:>");
}
if(Serial.available() > 0){
datamasuk2=Serial.readStringUntil('\n\n\n');
bataskonter1=datamasuk2.toInt();
Serial.print("delay =");
Serial.print(bataskonter1);
Serial.println("ms");
for(int konter1 = bataskonter; konter1>0; konter1--){
digitalWrite(led,HIGH);
Serial.print(konter1);
delay(bataskonter1);
digitalWrite(led,LOW);
delay(bataskonter1);
}
Serial.print("done! ! !");
}
}
unsigned int hexToDec(String hexString) {
unsigned int decValue = 0;
int nextInt;
for (int i = 0; i < hexString.length(); i++) {
nextInt = int(hexString.charAt(i));
if(nextInt >=45 && nextInt<=57) nextInt=map(nextInt,45,57,0,9);
if(nextInt >=65 && nextInt<=70) nextInt=map(nextInt,65,70,10,15);
if(nextInt >=97 && nextInt<=102) nextInt=map(nextInt,97,102,10,15);
nextInt = constrain(nextInt, 0, 15);
decValue = (decValue * 16) + nextInt;
}
return decValue;
}
Berikut Hasil Compile :
gb1. Hasil Compile
Komunikasi Serial :
gb2. Saat di masukkan 8 kali nyala led dan delay 500ms
Tidak ada komentar:
Posting Komentar