EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 281

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
281
Chapter 27 Solder Circuit Board
www.freenove.com
support@freenove.com
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <wiringPi.h>
#include <stdio.h>
#include <wiringShift.h>
#include <unistd.h>
#define dataPin 0 //DS Pin of 74HC595(Pin14)
#define latchPin 2 //ST_CP Pin of 74HC595(Pin12)
#define clockPin 3 //SH_CP Pin of 74HC595(Pin11)
//Define an array to save the pulse width of LED. Output the signal to the 8 adjacent
LEDs in order.
const int pluseWidth[]={0,0,0,0,0,0,0,0,64,32,16,8,4,2,1,0,0,0,0,0,0,0,0};
void outData(int8_t data){
digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,LSBFIRST,data);
digitalWrite(latchPin,HIGH);
}
int main(void)
{
int i,j,index; //index:current position in array pluseWidth
int moveSpeed = 100; //move speed delay, the greater, the slower
long lastMove; //Record the last time point of the move
if(wiringPiSetup() == -1){ //when initialize wiring failed, print message to screen
printf("setup wiringPi failed !");
return 1;
}
pinMode(dataPin,OUTPUT);
pinMode(latchPin,OUTPUT);
pinMode(clockPin,OUTPUT);
index = 0; //Starting from the array index 0
lastMove = millis(); //the start time
while(1){
if(millis() - lastMove > moveSpeed) { //speed control
lastMove = millis(); //Record the time point of the move
index++; //move to next
if(index > 15) index = 0; //index to 0
}
for(i=0;i<64;i++){ //The cycle of PWM is 64 cycles
int8_t data = 0; //This loop of output data
for(j=0;j<8;j++){ //Calculate the output state of this loop
if(i < pluseWidth[index+j]){ //Calculate the LED state according to
the pulse width
data |= 0x01<<j ; //Calculate the data
}

Table of Contents