Skip to content

Instantly share code, notes, and snippets.

@kakittwo
Last active Nov 23, 2018
Embed
What would you like to do?
led.ino
int n = 4;
int sum =0 ;
void setup() {
for (int i = 0; i < n; i++) {
pinMode(10+ i, OUTPUT);
}
for (int i = 1 ; i <= n-1 ; i++){
sum += i;
}
for (int i = 0; i < sum; i++) {
pinMode(i, OUTPUT);
}
for (int kk =0 ; kk < sum ; kk++){
digitalWrite(kk, LOW);
}
for (int kk =0 ; kk < n ; kk++){
digitalWrite(10 + kk, LOW);
}
}
void loop() {
for (int i = 0; i < n-1; i++){
for (int j = i + 1 ; j < n; j++){
for (int k = 0 ; k < sum ; k++){
if (k != i + int( 0.5*(j-1-i)*(2*n-j +i) )) {
digitalWrite(k, LOW);
}else{
digitalWrite(k, HIGH);
}
}
for (int kk = 0 ; kk < n ; kk++){
if (kk != i && kk != j) {
digitalWrite(10+kk, LOW);
}else{
digitalWrite(10+kk, HIGH);
}
}
delay(1000);
}
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment