Is there any way to make this more efficient?

Thread Starter

Zane Finner

Joined Jan 29, 2018
30
https://www.tinkercad.com/things/60luoDuYcUo-terrific-stantia-duup/ Please post comments of any kind including constructive critisism. I need advice.

Code:
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(5, LOW);
digitalWrite(12, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(13, LOW);
digitalWrite(11, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(12, LOW);
digitalWrite(10, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(11, LOW);
digitalWrite(9, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(10, LOW);
digitalWrite(8, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(9, LOW);
digitalWrite(7, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(8, LOW);
digitalWrite(6, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(7, LOW);
digitalWrite(5, HIGH);
delay(150); // Wait for 150 millisecond(s)
digitalWrite(6, LOW);
}
 

jpanhalt

Joined Jan 18, 2008
11,087
I don't do C, but it looks like you set two bits and rotate them though a loop of 9 or 10 states. Are state '0' and state '9' meant to be the same? What are the states of #5 at the start and #13 at the end? In other words, are the bits by default = 0, does each state have 2 bits set, or are there 2 states that only have one bit set?

Assuming it is meant as a loop with 9 (not 10) distinct states, and 2 bits in each state set, you can simply code that as rotations. In Assembly, that would be straight forward. Don't know about C.
 
Top