Skip to content

Commit

Permalink
added digital read and digital listing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfisher committed Jul 23, 2011
1 parent 1cfe49a commit 37f5fc2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Version 0.3 (23 July, 2011)
* refactored all the printing to use a generic Print object so won't matter if you use Serial or Ethernet
* added global ethclient var so ethernet functions have access to them.
* added a heap of anti-telnet garbling code to command parser.
* added digital read and list all digital pin functions


Version 0.2 (22 July, 2011)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Issues should be raised as via the issue tracker at GitHub on the link above.
To Do:
------

* Add digital read
* add ability to cycle from one state to another via pwm shifting
* be able to set network params
* move everything to a library to make it more useful
* refactor ls, read and write functions to be more generic and free up some space.
38 changes: 36 additions & 2 deletions arduino_command_server_pde/arduino_command_server_pde.pde
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ void setup() {
com[2]=(Command){"ANR", "Reads a specific analog pin", command_analog_read};
com[3]=(Command){"ANW", "Writes to an analog pin", command_analog_write};
com[4]=(Command){"PINM", "Sets the mode of a digital pin [pin IN|OUT]", command_setmode};
com[5]=(Command){"DIGW", "Writes to the digital pin", command_digital_write};
com[6]=(Command){"QUIT", "Quits this session gracefully", command_quit};
com[5]=(Command){"LSD", "Lists status of all digital pins", command_list_digital};
com[6]=(Command){"DIGW", "Writes to the digital pin", command_digital_write};
com[7]=(Command){"DIGR", "Reads the specified digital pin", command_digital_read};
com[8]=(Command){"QUIT", "Quits this session gracefully", command_quit};

}

Expand Down Expand Up @@ -281,6 +283,38 @@ void command_setmode(String args) {
client->println("503 Please use IN or OUT only");
}

void command_list_digital(String args) {
// list the current status of all the analog pins.
client->println("200 Digital Read all pins");
client->println("210 If using ethernet pins 10-13 are used");
for (int i=0; i<20; i++) {
client->print("211 D");
client->print(i);
client->print(" ");
client->println(digitalRead(i));
}
}

void command_digital_read(String args) {
// reads a specified digital pin
// argument passed in should simply be a number and it's that one we read.
// we do need to get both chars though because it can be 2 digits
if (args.length() <= 0) {
client->println("501 Pin number not supplied");
return;
}
if (args.length() > 2) {
client->println("502 Pin range too high or incorrect");
return;
}
// just convert it and if it gets something nasty it will go to zero.
int pin = atoi(&args[0]);
client->print("200 Digital read pin #");
client->println(pin);
client->print("211 ");
client->println(digitalRead((pin)));
}

void command_digital_write (String args) {
// sets a digital pin high or low based on what value is passed.
// params are the pin number then HIGH or LOW
Expand Down

0 comments on commit 37f5fc2

Please sign in to comment.