Record a very interesting algorithm written by yourself, and record interesting Algorithms
Description:
The project is an electronic bus stop card. It uses LED lights to represent the bus stop and uses lights to display the location of the car.
For example:
It took a day to write the algorithm for implementing the "Number of intervals" function. Four lines were written, so it was very interesting.
Question:
Use an 8-Bit Array with a length of 10 to save the status of the 80 lights. uint8_t Output_Data [10] = 0;
The first eight lights from left to right are stored in Output_Data [9], and so on. The last eight lights are stored in Output_Data [0.
For example, to enable the first light (the first light is on the left by default), Output_Data [9] = 0x80;
When the last light is on, Output_Data [0] = 0x01;
Requirement: Increase the number of intervals function, that is, the number of fixed intervals between bus stops
After the algorithm is implemented, the data in Output_Data [] changes to the data that adapts to the number of intervals.
For example, if Output_Data is {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFF, 0xFF}, the first 16 stations are on.
When the number of intervals is 1, after the algorithm goes through, Output_Data should be {0 x, 0 x, 0 x, 0 x, 0x00, 0xAA, 0xAA, 0xAA, 0xAA} (Change 1111 1111 to 1010 1010 1010) (put each byte forward from the back to Output_Data)
When the number of intervals is 2, output_Data should be {0x00,0x00,0x00,0x00,0x24,0x49,0x92,0x24,0x49,0x92} (Change 1111 1111 to 1001 0010 0100 1001) (No, it is not 0x92,0x49,0x24 in Output_Data [], but reversed)
The number of intervals is not fixed, so data must be converted to any number of intervals (the number of intervals is given). Of course, the number of intervals does not exceed 78. (^_^)
Ps: raw data is not separated, but it is actual. If the line interval is 1, only the first half has data, with the interval of 9, only one byte of data is allowed.
I wrote this article, and you are welcome to criticize and correct it.
I is the line, which has nothing to do with this question. Interval is the number of intervals.