Skip to content

Instantly share code, notes, and snippets.

View biskandar's full-sized avatar
💭
Spring Boot + Kubernetes = DevOps

Benny biskandar

💭
Spring Boot + Kubernetes = DevOps
View GitHub Profile
@biskandar
biskandar / 2012010401.c
Created October 6, 2012 06:17
Using I2C as Communication Link between Arduinos 2012010401
#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
@biskandar
biskandar / 2012010402.c
Created October 6, 2012 06:39
Using I2C as Communication Link between Arduinos 2012010402
#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 ) ;
@biskandar
biskandar / 2012100801.c
Created October 8, 2012 11:45
Simplified webserver module using Webduino library 2012100801
#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() {
@biskandar
biskandar / 2012100802.c
Created October 8, 2012 11:48
Simplified webserver module using Webduino library 2012100802
#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
@biskandar
biskandar / 2012100803.c
Created October 8, 2012 12:17
Simplified webserver module using Webduino library 2012100803
// 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 = " ) ;
@biskandar
biskandar / 2012100804.c
Created October 8, 2012 12:25
Simplified webserver module using Webduino library 2012100804
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 ;
}
@biskandar
biskandar / 2012101001.c
Created October 10, 2012 13:29
Make your arduino and his best ethernet friend talk to the world 2012101001
#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 ;
@biskandar
biskandar / 2012101601.c
Created October 16, 2012 08:57
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101601
// 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
@biskandar
biskandar / 2012101602.c
Created October 16, 2012 08:58
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101602
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
@biskandar
biskandar / 2012101603.c
Created October 16, 2012 09:00
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101603
void readAnalogs() {
for ( int idxAnalogs = 0 ; idxAnalogs < maxAnalogs ; idxAnalogs++ ) {
arrAnalogs[idxAnalogs] = analogRead( idxAnalogs ) ;
}
}
void infoAnalogs() {
Serial.print( "[" ) ;
Serial.print( millis() ) ;
Serial.print( "] Analogs : " ) ;