Arduino Code to Matlab Code

1 vue (au cours des 30 derniers jours)
kev
kev le 15 Mai 2014
Can you guys help me to make this arduino code work for matlab? It is a LED Dice that generates random number of LED Lights between 1-6.
int pinLeds1 = 10;
int pinLeds2 = 9;
int pinLeds3 = 7;
int pinLed4 = 8;
int buttonPin = 6;
int buttonState;
long ran;
int time = 2000;
void setup()
{
pinMode (pinLeds1, OUTPUT);
pinMode (pinLeds2, OUTPUT);
pinMode (pinLeds3, OUTPUT);
pinMode (pinLed4, OUTPUT);
pinMode (buttonPin, INPUT);
randomSeed(analogRead(0));
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH){
ran = random(1, 7);
if (ran == 1){
digitalWrite (pinLed4, HIGH);
delay (time);
}
if (ran == 2){
digitalWrite (pinLeds1, HIGH);
delay (time);
}
if (ran == 3){
digitalWrite (pinLeds3, HIGH);
digitalWrite (pinLed4, HIGH);
delay (time);
}
if (ran == 4){
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds3, HIGH);
delay (time);
}
if (ran == 5){
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds3, HIGH);
digitalWrite (pinLed4, HIGH);
delay (time);
}
if (ran == 6){
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds2, HIGH);
digitalWrite (pinLeds3, HIGH);
delay (time);
}
}
digitalWrite (pinLeds1, LOW);
digitalWrite (pinLeds2, LOW);
digitalWrite (pinLeds3, LOW);
digitalWrite (pinLed4, LOW);
}

Réponses (0)

Catégories

En savoir plus sur Setup and Configuration dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by