Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
softjei committed Aug 26, 2015
0 parents commit af67e33
Show file tree
Hide file tree
Showing 21 changed files with 931 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
# Cloudino-ArduinoLib
Binary file added examples/.DS_Store
Binary file not shown.
60 changes: 60 additions & 0 deletions examples/00.Templates/Base/Base.ino
@@ -0,0 +1,60 @@
#include<Cloudino.h>

Cloudino cdino;

#define SIR 10
#define ELE 11
#define PULSE 80 //micro seg
#define INTERV 1160 //milli seg


bolean eleon=false;
unsugned long ltime=0;

void sir(string msg)
{
if(msg=="on")
{
digitalWrite(SIR, LOW);
}else
{
digitalWrite(SIR, HIGH);
}
}

void ele(string msg)
{
if(msg=="on")
{
eleon=true;
}else
{
eleon=false;
}
}

void setup() {
pinMode(SIR, OUTPUT); //sirena
digitalWrite(SIR, HIGH);
pinMode(ELE, OUTPUT); //eletrica
digitalWrite(ELE, LOW);
cdino.on("sir",sir);
cdino.on("ele",ele);
cdino.begin();
ltime=millis();
}

void loop() {
cdino.loop();

if(eleon)
{
if((millis()-ltime)>INTERV)
{
ltime=millis();
digitalWrite(ELE, HIGH);
delayMicroseconds(PULSE);
digitalWrite(ELE, LOW);
}
}
}
28 changes: 28 additions & 0 deletions examples/01.Basic/Blink/Blink.ino
@@ -0,0 +1,28 @@
#include<Cloudino.h>

Cloudino cdino;

const long time = 1000; // Time milliseconds
const int ledPin = 13; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED

void blink()
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}

void setup() {
pinMode(ledPin, OUTPUT);
cdino.setInterval(time,blink);
cdino.begin();
}

void loop() {
cdino.loop();
}
37 changes: 37 additions & 0 deletions examples/01.Basic/BlinkMix/BlinkMix.ino
@@ -0,0 +1,37 @@
#include<Cloudino.h>

Cloudino cdino;

const int ledPin = 13; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED

void blink()
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}

void setBlink1()
{
cdino.setTimer(200,blink,4,setBlink2);
}

void setBlink2()
{
cdino.setTimer(50,blink,4,setBlink1);
}

void setup() {
pinMode(ledPin, OUTPUT);
setBlink1();
cdino.begin();
}

void loop() {
cdino.loop();
}
19 changes: 19 additions & 0 deletions examples/02.Analog/AnalogSensor/AnalogSensor.ino
@@ -0,0 +1,19 @@
#include <Cloudino.h>

Cloudino cdino;

const int analogPin = A0; // Analog input pin that the potentiometer is attached to

void getSensor()
{
cdino.post("sensor",String(analogRead(analogPin)));
}

void setup() {
cdino.setInterval(10000,getSensor);
cdino.begin();
}

void loop() {
cdino.loop();
}
29 changes: 29 additions & 0 deletions examples/03.Post/Post/Post.ino
@@ -0,0 +1,29 @@
#include <Cloudino.h>

Cloudino cdino;


//|L|17|hola %d, JAVIER10
//|M5|helloS6|mundo!

void onmessage(String msg)
{
cdino.post("hola",msg);
}

void post()
{
cdino.post("hola","mundo");
}

// the setup function runs once when you press reset or power the board
void setup() {
cdino.on("hello",onmessage);
//cdino.setInterval(1000,post);
cdino.begin();
}

// the loop function runs over and over again forever
void loop() {
cdino.loop();
}
22 changes: 22 additions & 0 deletions examples/03.Post/PostLed/PostLed.ino
@@ -0,0 +1,22 @@
#include "Cloudino.h"

Cloudino cdino;

void led(String msg)
{
if(msg=="on")digitalWrite(13, HIGH);
else digitalWrite(13, LOW);
cdino.post("led",msg);
}

void setup()
{
pinMode(13, OUTPUT);
cdino.on("led",led);
cdino.begin();
}

void loop()
{
cdino.loop();
}
25 changes: 25 additions & 0 deletions examples/04.Sensors/DHT11/DHT11.ino
@@ -0,0 +1,25 @@
#include <Cloudino.h>
#include <dht11.h>

#define DHT11PIN 8

Cloudino cdino;
dht11 DHT11;

void getSensor()
{
int chk = DHT11.read(DHT11PIN);
cdino.post("temperature",String((float)DHT11.temperature,2));
cdino.post("humidity",String((float)DHT11.humidity,2));
}

void setup()
{
cdino.setInterval(10000,getSensor);
cdino.begin();
}

void loop()
{
cdino.loop();
}
28 changes: 28 additions & 0 deletions examples/04.Sensors/DHT11_2/DHT11_2.ino
@@ -0,0 +1,28 @@
#include <Cloudino.h>
#include <dht11.h>

#define DHT11PIN 8

Cloudino cdino;
dht11 DHT11;

void getSensor()
{
int chk = DHT11.read(DHT11PIN);
String cnt="{\"attributes\":[";
cnt+="{\"name\":\"temperature\",\"type\":\"xsd:float\",\"value\":\""+String((float)DHT11.temperature,2)+"\"},";
cnt+="{\"name\":\"humidity\",\"type\":\"xsd:float\",\"value\":\""+String((float)DHT11.humidity,2)+"\"}";
cnt+="]}";
cdino.post("$CONTENT",cnt);
}

void setup()
{
cdino.setInterval(10000,getSensor);
cdino.begin();
}

void loop()
{
cdino.loop();
}
Binary file added examples/04.Sensors/RFID/.DS_Store
Binary file not shown.
102 changes: 102 additions & 0 deletions examples/04.Sensors/RFID/RFID.ino
@@ -0,0 +1,102 @@

/******************************************
PURPOSE: Learn to use the MF522-AN RFID card reader
Created by Rudy Schlaf for www.makecourse.com
DATE: 2/2014
*******************************************/

/*
* This sketch uses the MFRC522 Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
* The library file MFRC522.h has a wealth of useful info. Please read it.
* The functions are documented in MFRC522.cpp.
*
* Based on code Dr.Leong ( WWW.B2CQSHOP.COM )
* Created by Miguel Balboa (circuitito.com), Jan, 2012.
* Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013 (Translation to English, refactored, comments, anti collision, cascade levels.)
*
* This library has been released into the public domain.
*/


#include <SPI.h>//include the SPI bus library
#include <MFRC522.h>//include the RFID reader library

#define SS_PIN 10 //slave select pin
#define RST_PIN 5 //reset pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // instatiate a MFRC522 reader object.
MFRC522::MIFARE_Key key;//create a MIFARE_Key struct named 'key', which will hold the card information


void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card (in case you wonder what PCD means: proximity coupling device)
Serial.println("Scan a MIFARE Classic card");

// Prepare the security key for the read and write functions - all six key bytes are set to 0xFF at chip delivery from the factory.
// Since the cards in the kit are new and the keys were never defined, they are 0xFF
// if we had a card that was programmed by someone else, we would need to know the key to be able to access it. This key would then need to be stored in 'key' instead.

for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;//keyByte is defined in the "MIFARE_Key" 'struct' definition in the .h file of the library
}

}

int block=2;//this is the block number we will write into and then read. Do not write into 'sector trailer' block, since this can make the block unusable.

byte blockcontent[16] = {"makecourse_____"};//an array with 16 bytes to be written into one of the 64 card blocks is defined
//byte blockcontent[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//all zeros. This can be used to delete a block.
byte readbackblock[18];//This array is used for reading out a block. The MIFARE_Read method requires a buffer that is at least 18 bytes to hold the 16 bytes of a block.

void loop()
{

/*****************************************establishing contact with a tag/card**********************************************************************/

// Look for new cards (in case you wonder what PICC means: proximity integrated circuit card)
if ( ! mfrc522.PICC_IsNewCardPresent()) {//if PICC_IsNewCardPresent returns 1, a new card has been found and we continue
return;//if it did not find a new card is returns a '0' and we return to the start of the loop
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {//if PICC_ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
return;//if it returns a '0' something went wrong and we return to the start of the loop
}

// Among other things, the PICC_ReadCardSerial() method reads the UID and the SAK (Select acknowledge) into the mfrc522.uid struct, which is also instantiated
// during this process.
// The UID is needed during the authentication process
//The Uid struct:
//typedef struct {
//byte size; // Number of bytes in the UID. 4, 7 or 10.
//byte uidByte[10]; //the user ID in 10 bytes.
//byte sak; // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
//} Uid;

Serial.println("card selected");

/*****************************************writing and reading a block on the card**********************************************************************/

writeBlock(block, blockcontent);//the blockcontent array is written into the card block
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

//The 'PICC_DumpToSerial' method 'dumps' the entire MIFARE data block into the serial monitor. Very useful while programming a sketch with the RFID reader...
//Notes:
//(1) MIFARE cards conceal key A in all trailer blocks, and shows 0x00 instead of 0xFF. This is a secutiry feature. Key B appears to be public by default.
//(2) The card needs to be on the reader for the entire duration of the dump. If it is removed prematurely, the dump interrupts and an error message will appear.
//(3) The dump takes longer than the time alloted for interaction per pairing between reader and card, i.e. the readBlock function below will produce a timeout if
// the dump is used.

//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));//uncomment this if you want to see the entire 1k memory with the block written into it.

readBlock(block, readbackblock);//read the block back
Serial.print("read block: ");
for (int j=0 ; j<16 ; j++)//print the block contents
{
Serial.write (readbackblock[j]);//Serial.write() transmits the ASCII numbers as human readable characters to serial monitor
}
Serial.println("");


}

0 comments on commit af67e33

Please sign in to comment.