I need help converting this arduino code into matlab code. The set up has two re
ID: 3550858 • Letter: I
Question
I need help converting this arduino code into matlab code.
The set up has two resistors(10&330) with a button and a led.
Here is what I have so far......
a = arduino('COM4');
a.pinMode(13,'OUTPUT');
a.pinMode(5,'INPUT');
while isvalid(a)
..I think it is right up to here.......
a.digitalWrite(13, led);
a.digitalRead(5);
=======same as picture==================
#define LED 13 // the pin for the LED
#define BUTTON 5 // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}
void loop(){
val = digitalRead(BUTTON); // read input value and store it
// check whether the input is HIGH (button pressed)
if (val == HIGH) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);
}
}
===================================
Explanation / Answer
a = arduino('COM4');
a.pinMode(13,'output'); % 13 pin output
a.pinMode(5,'input'); % 5th pin input
loop=1; % variable for looping
val=0; % val will be used to store the state
while loop==1
val=a.digitalRead(5); % read button
if val==1 % if val is high
a.digitalWrite(13,1); % write high on 13th pin
else
a.digitalWrite(13,0); % write low on 13th pin
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.