Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 10 months ago.
Random number in C kl25z every execution
I want to create a SIMON GAME with my KL25Z using TSI and LED RGB. I have this code but only work if I clic " compile " once, but I WANT ACTIVE RANDOM LED EVERY TIME THAT I TOUCH TSI Help me, please! Lot of thanks!
- include "mbed.h"
- include "TouchButton.h"
- include "time.h" I DON'T NO IF THIS LIBRARY IS WORKING
- include "stdlib.h" I DON'T NO IF THIS LIBRARY IS WORKING
- define NUM_LED 3
DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myRGB[NUM_LED] = {myled1, myled2, myled3};
int n;
int main(void) {
TouchButton TButton; int n;
srand(time(NULL)); n = rand()%NUM_LED;
int key=0; while (true) {
key=TButton.PresedButton();
No touch TSI if(key==0) { myled1 = 1; don't light myled2 = 1; myled3 = 1; } else if(key==1) touch TSI { myRGB[n] = 0; put random led in high
} } }