7 years, 11 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!

  1. include "mbed.h"
  2. include "TouchButton.h"
  3. include "time.h" I DON'T NO IF THIS LIBRARY IS WORKING
  4. include "stdlib.h" I DON'T NO IF THIS LIBRARY IS WORKING
  1. 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

} } }

Be the first to answer this question.