Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SakuraAlpha mbed
main.cpp
- Committer:
- sakurafan
- Date:
- 2016-06-03
- Revision:
- 1:dfd0aa5bc3ee
- Parent:
- 0:bd9a005d4efc
File content as of revision 1:dfd0aa5bc3ee:
/* SAKURA Internet IoT Alpha Communication Module
*
* Copyright (c) SAKURA Internet Inc.
* The MIT License (MIT)
* https://github.com/sakura-internet/SakuraAlphaArduino
*
* https://iot.sakura.ad.jp/
*
* Porting to mbed by sakurafan. 2016
*/
#include "mbed.h"
#include "SakuraAlpha.h"
#define BUF_LEN 16
SakuraAlphaI2C sakura(p28, p27); // sda, scl
/*
I2C i2c(p28, p27); // sda, scl
SakuraAlphaI2C sakura(i2c); // i2c
*/
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
int main () {
uint32_t cnt = 0;
uint8_t updated[BUF_LEN];
pc.baud(115200);
pc.printf("Waiting to come online...\r\n");
for(;;){
if( sakura.getNetworkStatus() == 1 ) break;
myled = !myled;
wait_ms(1000);
}
myled = 1;
for (;;) {
cnt++;
pc.printf("%d\r\n", cnt);
sakura.writeChannel(0,cnt);
sakura.writeChannel(1,cnt);
sakura.writeChannel(2,cnt);
wait_ms(250);
int num_updated = sakura.getUpdatedChannels(updated, BUF_LEN);
pc.printf("%d updated channels: ", num_updated);
for (int i = 0; i < min(num_updated,BUF_LEN); i++) {
pc.printf(" %d", updated[i]);
}
pc.printf("\r\n");
char type=0;
uint8_t value[8]={0};
sakura.readChannel(0, &type, value);
for (int i = 0; i < 8; i++) {
pc.printf(" %x", value[i]);
}
pc.printf(" type: %d\r\n", type);
wait_ms(250);
pc.printf("Tx[0] status: %d\r\n", sakura.getTxChannelStatus(0));
sakura.transmit(TRANSMIT_ONCE);
wait_ms(250);
num_updated = sakura.getUntransmittedChannels(updated, BUF_LEN);
pc.printf("%d untransmitted channels: ", num_updated);
for (int i = 0; i < min(num_updated,BUF_LEN); i++) {
pc.printf(" %d", updated[i]);
}
pc.printf("\r\n");
wait_ms(1000);
pc.printf("\r\n");
}
}