Go Down

Topic: Arduino Dummy Terminal for gUi Help (Read 826 times) previous topic - next topic

JB_AU

The following sketch i found on the net, from somewhere ??? If it's you, my apologies .
I have edited the sketch to make it more ledge-able.

sketch.ino
Code: [Select]

String pinnum = "";
String commands = "";
String instruct = "";
int value = 0;
int pin;


void setup(){
  Serial.begin(9600);
}

void loop(){
  char inchar;
  int count = 0;
  if(Serial.available() > 0){
    while(inchar != '\n'){
      if (Serial.available()){
        inchar = Serial.read();
        if(inchar == '\n'){
          break;
        }
        if(count<4){
          commands += (char)inchar;
          count++;
        }
        else{
          instruct += (char)inchar;
        }
      }
    }
    //value = instruct.toInt();
    pinnum = commands.substring(2,4);
    pin = pinnum.toInt();   
    switch(commands.charAt(0)){
    case 'a':     
      analog();
      break;
    case 'd':
      digital();
      break;
    }
    clearall();
  } 
}

void analog(){
  switch(commands.charAt(1)){
  case 'r':
    value = analogRead(pin);
    Serial.println(value);
    break;
  case 'w':
    Serial.print(pin);
    Serial.println("ok");
    pinMode(pin,OUTPUT);
    value = instruct.toInt();
    analogWrite(pin,value);
    break;
  }
}

void digital(){
  switch(commands.charAt(1)){
  case 'r':
    pinMode(pin,INPUT);
    value = digitalRead(pin);
    Serial.println(value);
    break;
  case 'w':
    Serial.print(pin);
    Serial.println("ok");
    pinMode(pin,OUTPUT);
    value = instruct.toInt();
    digitalWrite(pin,value);
    break;
  }
}

void clearall(){
  commands = "";
  instruct = "";
  pinnum = "";
}


I have played with this to make and understand gui development easier, i am mixing this with my own code, this gives me an extra layer of control-ability. By itself , it just makes the arduino a simple terminal , waiting for instructions from U. The U in gUi.
I have used this in Auto-IT, Realbasic, Terminal & Flowstone (which is what i am currently using).

From terminal or your preferred IDE, The following are used, when a serial connection has been established;

d = digital
a = analog
w = write
r = read

dw12+1   //digitalwrite pin 12 HIGH
dr12   //digitalread pin 12
aw0+10   //analoglwrite pin 0 value of 10
ar0   //analoglread pin 0

This adds flexibility, giving you the chance to simulate situations without any extra components needed.

I exclude the use of Pins D0, D1 & D13, i exclude the RX/TX lines & Pin 13 as;

dw13+0 //make 13 low
dr13 // you get 0/low but the ping goes high after reading  :~

I hope this helps somebody, because it is reallllllly helping me.

mrburnette

#1
Jun 30, 2013, 08:06 pm Last Edit: Jun 30, 2013, 08:14 pm by mrburnette Reason: 1
http://n.mtng.org/ele/arduino/iarduino.html
Check it out

IF YOU ONLY want read-only for all ports, then HID is useful:

http://forum.arduino.cc/index.php?topic=135623.msg1032421#msg1032421


- Ray

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy