Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte led1 = 2;
- const byte led2 = 3;
- const byte led3 = 4;
- const byte led4 = 5;
- const byte led5 = 6;
- const byte led6 = 7;
- const byte led7 = 8;
- const byte led8 = 9;
- int angka;//[10];
- int ar_angka[10];
- int i=0;
- void setup() {
- // put your setup code here, to run once:
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- pinMode(led4, OUTPUT);
- pinMode(led5, OUTPUT);
- pinMode(led6, OUTPUT);
- pinMode(led7, OUTPUT);
- pinMode(led8, OUTPUT);
- Serial.begin(115200);
- angka = 255;
- }
- void loop() {
- // put your main code here, to run repeatedly
- for(i = 0; angka>0; i++){
- ar_angka[i] = angka%2;
- angka=angka/2;
- }
- Serial.print("jumlah i pertama: ");
- Serial.println(i);
- for(i = i-1; i>=0; i--){
- Serial.print(ar_angka[i]);
- }
- Serial.println();
- Serial.print("jumlah i kedua: ");
- Serial.println(i);
- digitalWrite(led1, ar_angka[0]);
- digitalWrite(led2, ar_angka[1]);
- digitalWrite(led3, ar_angka[2]);
- digitalWrite(led4, ar_angka[3]);
- digitalWrite(led5, ar_angka[4]);
- digitalWrite(led6, ar_angka[5]);
- digitalWrite(led7, ar_angka[6]);
- digitalWrite(led8, ar_angka[7]);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement