User Manual
102
Get into the folder of the code.
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C
Next, Compile the Code
make 14_dice
Run
sudo ./14_dice
Code Explanation
void randomISR(void){ // An interrupt function, run when the interrupt happens
flag = 1; // flag represents the state of the button
}
if(wiringPiISR(TouchPin, INT_EDGE_FALLING, &randomISR)){ //Set an interrupt here as the
falling edge for TouchPin. When the interrupt happens, execute the function randomISR().
printf("Unable to setup ISR : %s\n", strerror(errno));
return 1;
}
srand(time(NULL));
num = rand() % 6;
// Two functions here: One is the srand function, which is used before calling function
rand() and used as seed for the random number generator; while the other is rand(),
which is a function to generate the random number. Usually, these two functions are used
together to generate the random number. Thus a random number of 0-6 will be displayed on
the 7-segment display.
For Python users:
Step 2: Get into the folder of the code.
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python
Step 3: Run
sudo python 14_dice.py
Code Explanation
import random # use this function to generate the random number
SegCode = [0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d] # Define a segment code from 1 to 6
in Hexadecimal
GPIO.add_event_detect(TouchPin, GPIO.RISING, callback = randomISR, bouncetime = 20) #
Set an interrupt, and the rising edge for TouchPin. When the interrupt happens, execute
the function randomISR(). Set bouncetime for button to 20ms.
def randomISR(channel): # Interrupt calling the function
global flag
SunFounder