This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
// preparing for which slave device | |
// need to be connected | |
int slaveId = 0 ; | |
void setup() { | |
Serial.begin( 9600 ) ; | |
while ( !Serial ) ; | |
// Run as I2C Master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
void setup() { | |
Serial.begin( 9600 ) ; | |
while ( !Serial ) ; | |
// run as I2C Slave with id = 1 | |
int slaveId = 1 ; | |
Wire.begin( slaveId ) ; | |
// setup callback function | |
Wire.onReceive( onWireReceive ) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SPI.h" | |
#include "Ethernet.h" | |
#include "WebServer.h" | |
#include "aJSON.h" | |
// prepare for the ethernet profile | |
static uint8_t mac[] = { 0x00 , 0x08, 0xDC, 0x00, 0x00, 0x09 } ; | |
static uint8_t ip[] = { 169, 254, 62, 169 } ; | |
void setup() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SPI.h" | |
#include "Ethernet.h" | |
#include "WebServer.h" | |
#include "aJSON.h" | |
// prepare for the ethernet profile | |
static uint8_t mac[] = { 0x00 , 0x08, 0xDC, 0x00, 0x00, 0x09 } ; | |
static uint8_t ip[] = { 169, 254, 62, 169 } ; | |
// prepare for webserver with webduino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prepare for the default command request | |
void defaultCommand( WebServer &webserver , WebServer::ConnectionType connType , char *tailUrl , bool tailComplete ) { | |
Serial.print( "New Command: " ) ; | |
// first, accepting all kind of request | |
webserver.httpSuccess() ; | |
// validate based on http method, | |
// only GET or POST is allow to continue | |
Serial.print( "connType = " ) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aJsonObject *jsonResponse( char *statusCode , char *statusDesc ) { | |
aJsonObject *jsonRoot = aJson.createObject() ; | |
aJson.addNumberToObject( jsonRoot , "millis" , (int) millis() ) ; | |
aJson.addStringToObject( jsonRoot , "status-code" , statusCode ) ; | |
aJson.addStringToObject( jsonRoot , "status-desc" , statusDesc ) ; | |
return jsonRoot ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <ICMPPing.h> | |
// prepare for tcp connection | |
byte mac[] = { 0x00, 0x08, 0xDC, 0x00, 0x00, 0x09 } ; | |
// prepare for the ping | |
SOCKET socket = 0 ; | |
int pingTimeout = 4 ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prepare for looping without delay | |
long curMillis = 0 ; | |
int ctrSeconds = 0 , maxSeconds = 100 ; | |
// prepare for reading analog data | |
int maxAnalogs = 6 ; | |
int arrAnalogs[] = { 0 , 0 , 0 , 0 , 0 , 0 } ; | |
int secAnalogs = 2 ; // in seconds | |
// prepare for debuging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
// validate every one second | |
long newMillis = millis() ; | |
if ( ( newMillis - curMillis ) > 1000 ) { | |
ctrSeconds = ctrSeconds + 1 ; | |
if ( ( ctrSeconds % secAnalogs ) == 0 ) { | |
readAnalogs() ; // <- read all analog pins | |
} | |
if ( ( ctrSeconds % secDebug ) == 0 ) { | |
infoAnalogs() ; // <- debug purpose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void readAnalogs() { | |
for ( int idxAnalogs = 0 ; idxAnalogs < maxAnalogs ; idxAnalogs++ ) { | |
arrAnalogs[idxAnalogs] = analogRead( idxAnalogs ) ; | |
} | |
} | |
void infoAnalogs() { | |
Serial.print( "[" ) ; | |
Serial.print( millis() ) ; | |
Serial.print( "] Analogs : " ) ; |
OlderNewer