Matlab & Arduino: Serial not working within switch statement


hi. doing serial communication between arduino , matlab, , can't figure out what's wrong arduino sketch.

code: [select]
#include <dht.h>

dht dht11_sensor;

const int dht11_pin = 14;
int trueval_inc;
int readval_inc;

void setup()
{
serial.begin(9600);
while(!serial){;}
}
void loop()
{
int *cmd_sel = new int;
if(serial.available() >= 2)
{
*(cmd_sel) = serial.read();
while(serial.available() != 0) {serial.read();}
serial.println(*cmd_sel);
               switch(*cmd_sel)
               {
                 case 1: serial.println(100);
                 break;
               }
}
}

here's did. sketch running on arduino, used fprintf in matlab , send value of '1' on serial. arduino must go inside if statement, since matlab (as realized) sends value of '10' (new line '\n'). first occurrence of serial.println must output value of '1' (and did). *cmd_sel equivalent 1, program not go , print 100 value serially. don't know why code not go inside case statement. thanks

moderator edit: [code] [/code] tags added.

i tried removing pointer on cmd_sel, , worked...i don't understand difference between *cmd_sel , cmd_sel when first dereferences memory location , gets integer value, , second cmd_sel directly gets integer value stored in variable.


Arduino Forum > Using Arduino > Programming Questions > Matlab & Arduino: Serial not working within switch statement


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support