This program simulates a dual dice throw by pushing the 2 buttons on the QW dev kit. The results of the throw are shown in binary on the leds, printed in the console window and transmitted via Sigfox.

Dependencies:   mbed

Fork of QW-BinaryDices by Quicksand

QW Binary Dices

This program simulates a dual dice throw by pushing the 2 buttons on the QW dev kit. The results of the throw are shown in binary on the leds, printed in the console window and transmitted via Sigfox.

Code explanation

The program starts with the initialisation/declaration of the leds and pushbuttons. Also the necessary function prototypes and serial communications are declared. After that, the program enters an infinite loop and waits till both buttons have been pushed. Once both buttons have been pushed, the result is shown in binary on the leds (LED_3 = LSB), printed in the console window and transmitted via Sigfox. When the Sigfox message is transmitted, the program is ready to throw the dices again.

Sigfox message payload

First there is the "04", this is the Quicksand ID of the example program. This is used by Quicksand to keep track of our example programs. The second value that is transmitted is the number that was thrown by the dices.

More information and other example code can be found on the component page by clicking the link below: https://developer.mbed.org/components/QW-SIGFOX-Development-Kit/

Files at this revision

API Documentation at this revision

Comitter:
quicksandjonas
Date:
Tue Dec 13 16:52:23 2016 +0000
Parent:
0:6c17d1a79f75
Commit message:
This program simulates a dual dice throw. The result is shown in binary on the 4 leds and is transmitted via Sigfox.

Changed in this revision

VCNL4010.cpp Show diff for this revision Revisions of this file
VCNL4010.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 6c17d1a79f75 -r 00a17f5a247c VCNL4010.cpp
--- a/VCNL4010.cpp	Thu Nov 05 09:40:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,287 +0,0 @@
-/*
-Copyright (c) 2012 Vishay GmbH, www.vishay.com
-author: DS, version 1.21
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "VCNL4010.h"
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0::VCNL40x0(PinName sda, PinName scl, unsigned char addr) : _i2c(sda, scl), _addr(addr) {
-   // _i2c.frequency(1000000);                                // set I2C frequency to 1MHz
-}
-
-VCNL40x0::~VCNL40x0() {
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetCommandRegister (unsigned char Command) {
-
-    _send[0] = REGISTER_COMMAND;                            // VCNL40x0 Configuration reister
-    _send[1] = Command;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadCommandRegister (unsigned char *Command) {
-
-    _send[0] = REGISTER_COMMAND;                            // VCNL40x0 Configuration register
-    _i2c.write(VCNL40x0_ADDRESS,_send, 1);                  // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1,_receive, 1);              // Read 1 byte on I2C
-
-    *Command = (unsigned char)(_receive[0]);
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadID (unsigned char *ID) {
-
-    _send[0] = REGISTER_ID;                                 // VCNL40x0 product ID revision register
-    _i2c.write(VCNL40x0_ADDRESS, _send, 1);                 // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1, _receive, 1);             // Read 1 byte on I2C
-
-    *ID = (unsigned char)(_receive[0]);
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetCurrent (unsigned char Current) {
-
-    _send[0] = REGISTER_PROX_CURRENT;                       // VCNL40x0 IR LED Current register
-    _send[1] = Current;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadCurrent (unsigned char *Current) {
-
-    _send[0] = REGISTER_PROX_CURRENT;                       // VCNL40x0 IR LED current register
-    _i2c.write(VCNL40x0_ADDRESS,_send, 1);                  // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1,_receive, 1);              // Read 1 byte on I2C
-
-    *Current = (unsigned char)(_receive[0]);
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetProximityRate (unsigned char ProximityRate) {
-
-    _send[0] = REGISTER_PROX_RATE;                          // VCNL40x0 Proximity rate register
-    _send[1] = ProximityRate;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetAmbiConfiguration (unsigned char AmbiConfiguration) {
-
-    _send[0] = REGISTER_AMBI_PARAMETER;                     // VCNL40x0 Ambilight configuration
-    _send[1] = AmbiConfiguration;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetInterruptControl (unsigned char InterruptControl) {
-
-    _send[0] = REGISTER_INTERRUPT_CONTROL;                  // VCNL40x0 Interrupt Control register
-    _send[1] = InterruptControl;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadInterruptControl (unsigned char *InterruptControl) {
-
-    _send[0] = REGISTER_INTERRUPT_CONTROL;                  // VCNL40x0 Interrupt Control register
-    _i2c.write(VCNL40x0_ADDRESS,_send, 1);                  // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1,_receive, 1);              // Read 1 byte on I2C
-
-    *InterruptControl = (unsigned char)(_receive[0]);
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetInterruptStatus (unsigned char InterruptStatus) {
-
-    _send[0] = REGISTER_INTERRUPT_STATUS;                   // VCNL40x0 Interrupt Status register
-    _send[1] = InterruptStatus;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetModulatorTimingAdjustment (unsigned char ModulatorTimingAdjustment) {
-
-    _send[0] = REGISTER_PROX_TIMING;                        // VCNL40x0 Modulator Timing Adjustment register
-    _send[1] = ModulatorTimingAdjustment;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadInterruptStatus (unsigned char *InterruptStatus) {
-
-    _send[0] = REGISTER_INTERRUPT_STATUS;                   // VCNL40x0 Interrupt Status register
-    _i2c.write(VCNL40x0_ADDRESS,_send, 1);                  // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1,_receive, 1);              // Read 1 byte on I2C
-
-    *InterruptStatus = (unsigned char)(_receive[0]);
-
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadProxiValue (unsigned int *ProxiValue) {
-
-    _send[0] = REGISTER_PROX_VALUE;                         // VCNL40x0 Proximity Value register
-    _i2c.write(VCNL40x0_ADDRESS, _send, 1);                 // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1, _receive, 2);             // Read 2 bytes on I2C
-    *ProxiValue = ((unsigned int)_receive[0] << 8 | (unsigned char)_receive[1]);
-
-    return VCNL40x0_ERROR_OK;
-
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadAmbiValue (unsigned int *AmbiValue) {
-
-    _send[0] = REGISTER_AMBI_VALUE;                          // VCNL40x0 Ambient Light Value register
-    _i2c.write(VCNL40x0_ADDRESS, _send, 1);                  // Write 1 byte on I2C
-    _i2c.read(VCNL40x0_ADDRESS+1, _receive, 2);              // Read 2 bytes on I2C
-    *AmbiValue = ((unsigned int)_receive[0] << 8 | (unsigned char)_receive[1]);
-
-    return VCNL40x0_ERROR_OK;
-
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetLowThreshold (unsigned int LowThreshold) {
-
-    unsigned char LoByte=0, HiByte=0;
-    
-    LoByte = (unsigned char)(LowThreshold & 0x00ff);
-    HiByte = (unsigned char)((LowThreshold & 0xff00)>>8);
-    
-    _send[0] = REGISTER_INTERRUPT_LOW_THRES;                // VCNL40x0 Low Threshold Register, Hi Byte
-    _send[1] = HiByte;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-    
-    _send[0] = REGISTER_INTERRUPT_LOW_THRES+1;              // VCNL40x0 Low Threshold Register, Lo Byte
-    _send[1] = LoByte;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::SetHighThreshold (unsigned int HighThreshold) {
-
-    unsigned char LoByte=0, HiByte=0;
-    
-    LoByte = (unsigned char)(HighThreshold & 0x00ff);
-    HiByte = (unsigned char)((HighThreshold & 0xff00)>>8);
-    
-    _send[0] = REGISTER_INTERRUPT_HIGH_THRES;               // VCNL40x0 High Threshold Register, Hi Byte
-    _send[1] = HiByte;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-    
-    _send[0] = REGISTER_INTERRUPT_HIGH_THRES+1;             // VCNL40x0 High Threshold Register, Lo Byte
-    _send[1] = LoByte;
-    _i2c.write(VCNL40x0_ADDRESS,_send, 2);                  // Write 2 bytes on I2C
-
-    return VCNL40x0_ERROR_OK;
-
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadProxiOnDemand (unsigned int *ProxiValue) {
-
-    unsigned char Command=0;
-
-    // enable prox value on demand
-    SetCommandRegister (COMMAND_PROX_ENABLE | COMMAND_PROX_ON_DEMAND);
- 
-    // wait on prox data ready bit
-    do {
-        ReadCommandRegister (&Command);                     // read command register
-    } while (!(Command & COMMAND_MASK_PROX_DATA_READY));
-
-    ReadProxiValue (ProxiValue);                            // read prox value
-
-    SetCommandRegister (COMMAND_ALL_DISABLE);               // stop prox value on demand
-    
-    return VCNL40x0_ERROR_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-VCNL40x0Error_e VCNL40x0::ReadAmbiOnDemand (unsigned int *AmbiValue) {
-
-    unsigned char Command=0;
-
-    // enable ambi value on demand
-    SetCommandRegister (COMMAND_PROX_ENABLE | COMMAND_AMBI_ON_DEMAND);
-
-    // wait on ambi data ready bit
-    do {
-        ReadCommandRegister (&Command);                     // read command register
-    } while (!(Command & COMMAND_MASK_AMBI_DATA_READY));
-
-    ReadAmbiValue (AmbiValue);                              // read ambi value    
-
-    SetCommandRegister (COMMAND_ALL_DISABLE);               // stop ambi value on demand    
-
-    return VCNL40x0_ERROR_OK;
-}
diff -r 6c17d1a79f75 -r 00a17f5a247c VCNL4010.h
--- a/VCNL4010.h	Thu Nov 05 09:40:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-/*
-Copyright (c) 2012 Vishay GmbH, www.vishay.com
-author: DS, version 1.2
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef VCNL40x0_H
-#define VCNL40x0_H
-
-#include "mbed.h"
-
-// Library for the Vishay Proximity/Ambient Light Sensor VCNL4010/4020
-// The VCNL4x00 is a I2C digital Proximity and Ambient Light Sensor in a small SMD package
-
-#define VCNL40x0_ADDRESS               (0x26) // 001 0011 shifted left 1 bit = 0x26
-
-// registers 
-#define REGISTER_COMMAND               (0x80)
-#define REGISTER_ID                    (0x81)
-#define REGISTER_PROX_RATE             (0x82)
-#define REGISTER_PROX_CURRENT          (0x83)
-#define REGISTER_AMBI_PARAMETER        (0x84)
-#define REGISTER_AMBI_VALUE            (0x85)
-#define REGISTER_PROX_VALUE            (0x87)
-#define REGISTER_INTERRUPT_CONTROL     (0x89)
-#define REGISTER_INTERRUPT_LOW_THRES   (0x8a)
-#define REGISTER_INTERRUPT_HIGH_THRES  (0x8c)
-#define REGISTER_INTERRUPT_STATUS      (0x8e)
-#define REGISTER_PROX_TIMING           (0x8f)
-#define REGISTER_AMBI_IR_LIGHT_LEVEL   (0x90)   // This register is not intended to be use by customer
-
-// Bits in Command register (0x80)
-#define COMMAND_ALL_DISABLE            (0x00)
-#define COMMAND_SELFTIMED_MODE_ENABLE  (0x01)
-#define COMMAND_PROX_ENABLE            (0x02)
-#define COMMAND_AMBI_ENABLE            (0x04)
-#define COMMAND_PROX_ON_DEMAND         (0x08)
-#define COMMAND_AMBI_ON_DEMAND         (0x10)
-#define COMMAND_MASK_PROX_DATA_READY   (0x20)
-#define COMMAND_MASK_AMBI_DATA_READY   (0x40)
-#define COMMAND_MASK_LOCK              (0x80)
-
-// Bits in Product ID Revision Register (0x81)
-#define PRODUCT_MASK_REVISION_ID       (0x0f)
-#define PRODUCT_MASK_PRODUCT_ID        (0xf0)
-
-// Bits in Prox Measurement Rate register (0x82)
-#define PROX_MEASUREMENT_RATE_2        (0x00)   // DEFAULT
-#define PROX_MEASUREMENT_RATE_4        (0x01)
-#define PROX_MEASUREMENT_RATE_8        (0x02)
-#define PROX_MEASUREMENT_RATE_16       (0x03)
-#define PROX_MEASUREMENT_RATE_31       (0x04)
-#define PROX_MEASUREMENT_RATE_62       (0x05)
-#define PROX_MEASUREMENT_RATE_125      (0x06)
-#define PROX_MEASUREMENT_RATE_250      (0x07)
-#define PROX_MASK_MEASUREMENT_RATE     (0x07)
-
-// Bits in Procimity LED current setting (0x83)
-#define PROX_MASK_LED_CURRENT          (0x3f)   // DEFAULT = 2
-#define PROX_MASK_FUSE_PROG_ID         (0xc0)
-
-// Bits in Ambient Light Parameter register (0x84)
-#define AMBI_PARA_AVERAGE_1            (0x00)
-#define AMBI_PARA_AVERAGE_2            (0x01)
-#define AMBI_PARA_AVERAGE_4            (0x02)
-#define AMBI_PARA_AVERAGE_8            (0x03)
-#define AMBI_PARA_AVERAGE_16           (0x04)
-#define AMBI_PARA_AVERAGE_32           (0x05)   // DEFAULT
-#define AMBI_PARA_AVERAGE_64           (0x06)
-#define AMBI_PARA_AVERAGE_128          (0x07)
-#define AMBI_MASK_PARA_AVERAGE         (0x07)
-
-#define AMBI_PARA_AUTO_OFFSET_ENABLE   (0x08)   // DEFAULT enable
-#define AMBI_MASK_PARA_AUTO_OFFSET     (0x08)
-
-#define AMBI_PARA_MEAS_RATE_1          (0x00)
-#define AMBI_PARA_MEAS_RATE_2          (0x10)   // DEFAULT
-#define AMBI_PARA_MEAS_RATE_3          (0x20)
-#define AMBI_PARA_MEAS_RATE_4          (0x30)
-#define AMBI_PARA_MEAS_RATE_5          (0x40)
-#define AMBI_PARA_MEAS_RATE_6          (0x50)
-#define AMBI_PARA_MEAS_RATE_8          (0x60)
-#define AMBI_PARA_MEAS_RATE_10         (0x70)
-#define AMBI_MASK_PARA_MEAS_RATE       (0x70)
-
-#define AMBI_PARA_CONT_CONV_ENABLE     (0x80)
-#define AMBI_MASK_PARA_CONT_CONV       (0x80)   // DEFAULT disable
-
-// Bits in Interrupt Control Register (x89)
-#define INTERRUPT_THRES_SEL_PROX       (0x00)
-#define INTERRUPT_THRES_SEL_ALS        (0x01)
-
-#define INTERRUPT_THRES_ENABLE         (0x02)
-
-#define INTERRUPT_ALS_READY_ENABLE     (0x04)
-
-#define INTERRUPT_PROX_READY_ENABLE    (0x08)
-
-#define INTERRUPT_COUNT_EXCEED_1       (0x00)   // DEFAULT
-#define INTERRUPT_COUNT_EXCEED_2       (0x20)
-#define INTERRUPT_COUNT_EXCEED_4       (0x40)
-#define INTERRUPT_COUNT_EXCEED_8       (0x60)
-#define INTERRUPT_COUNT_EXCEED_16      (0x80)
-#define INTERRUPT_COUNT_EXCEED_32      (0xa0)
-#define INTERRUPT_COUNT_EXCEED_64      (0xc0)
-#define INTERRUPT_COUNT_EXCEED_128     (0xe0)
-#define INTERRUPT_MASK_COUNT_EXCEED    (0xe0) 
-
-// Bits in Interrupt Status Register (x8e)
-#define INTERRUPT_STATUS_THRES_HI      (0x01)
-#define INTERRUPT_STATUS_THRES_LO      (0x02)
-#define INTERRUPT_STATUS_ALS_READY     (0x04)
-#define INTERRUPT_STATUS_PROX_READY    (0x08)
-#define INTERRUPT_MASK_STATUS_THRES_HI (0x01)
-#define INTERRUPT_MASK_THRES_LO        (0x02)
-#define INTERRUPT_MASK_ALS_READY       (0x04)
-#define INTERRUPT_MASK_PROX_READY      (0x08)
-
-typedef enum {
-    VCNL40x0_ERROR_OK = 0,               // Everything executed normally
-    VCNL40x0_ERROR_I2CINIT,              // Unable to initialise I2C
-    VCNL40x0_ERROR_I2CBUSY,              // I2C already in use
-    VCNL40x0_ERROR_LAST
-} VCNL40x0Error_e;
-
-
-class VCNL40x0 {
-public:
-// Creates an instance of the class.
-// Connect module at I2C address addr using I2C port pins sda and scl.
-
-    VCNL40x0 (PinName sda, PinName scl, unsigned char addr);
-
-// Destroys instance
-
-    ~VCNL40x0();
-
-// public functions
-
-    VCNL40x0Error_e Init (void);
-    
-    VCNL40x0Error_e SetCommandRegister (unsigned char Command);
-    VCNL40x0Error_e SetCurrent (unsigned char CurrentValue);
-    VCNL40x0Error_e SetProximityRate (unsigned char ProximityRate);
-    VCNL40x0Error_e SetAmbiConfiguration (unsigned char AmbiConfiguration);
-    VCNL40x0Error_e SetLowThreshold (unsigned int LowThreshold);
-    VCNL40x0Error_e SetHighThreshold (unsigned int HighThreshold);
-    VCNL40x0Error_e SetInterruptControl (unsigned char InterruptControl);
-    VCNL40x0Error_e SetInterruptStatus (unsigned char InterruptStatus);
-    VCNL40x0Error_e SetModulatorTimingAdjustment (unsigned char ModulatorTimingAdjustment);
-
-    VCNL40x0Error_e ReadID (unsigned char *ID);
-    VCNL40x0Error_e ReadCurrent (unsigned char *CurrentValue);
-    VCNL40x0Error_e ReadCommandRegister (unsigned char *Command);
-    VCNL40x0Error_e ReadProxiValue (unsigned int *ProxiValue);
-    VCNL40x0Error_e ReadAmbiValue (unsigned int *AmbiValue);
-    VCNL40x0Error_e ReadInterruptStatus (unsigned char *InterruptStatus);
-    VCNL40x0Error_e ReadInterruptControl (unsigned char *InterruptControl);
-    
-    VCNL40x0Error_e ReadProxiOnDemand (unsigned int *ProxiValue);
-    VCNL40x0Error_e ReadAmbiOnDemand (unsigned int *AmbiValue);
- 
-private:
-    I2C _i2c;
-    int _addr;
-    char _send[3];
-    char _receive[2];
-    
-};
-
-#endif
diff -r 6c17d1a79f75 -r 00a17f5a247c main.cpp
--- a/main.cpp	Thu Nov 05 09:40:10 2015 +0000
+++ b/main.cpp	Tue Dec 13 16:52:23 2016 +0000
@@ -1,48 +1,263 @@
+/* This program demonstrates how to use the board to simulate a dual dice throw.
+ * The result is displayed in binary on the leds and transmitted via Sigfox.
+ * Open a serial console to the board to see extra info.
+ */
+ 
 #include "mbed.h"
-#include "VCNL4010.h"
+
+#include <stdio.h>
+#include <stdlib.h>
 
+#define SER_BUFFER_SIZE 32
+
+/* The 4 onboard LEDs */
 DigitalOut LED_0 (PB_6);
 DigitalOut LED_1 (PA_7);
 DigitalOut LED_2 (PA_6);
 DigitalOut LED_3 (PA_5);
- 
-//Virtual serial port over USB
+
+/* The 2 user buttons */
+InterruptIn SW1(PA_8);
+InterruptIn SW2(PB_10);
+
+
+
+/* Function prototypes */
+void sw1interrupt();
+void sw2interrupt();
+void sertmout();
+bool modem_command_check_ok(char * command);
+void modem_setup();
+
+bool ser_timeout = false; 
+
+
+/* Serial port over USB */
 Serial pc(USBTX, USBRX);
+
+/* Serial connection to sigfox modem */
 Serial modem(PA_9, PA_10);
 
-// configure VCNL4010
-VCNL40x0 VCNL40x0_Device (PB_9, PB_8, VCNL40x0_ADDRESS);      // Define SDA, SCL pin and I2C address
+bool dice1 = false;
+bool dice2 = false;
+uint8_t dice1val;
+uint8_t dice2val;
+uint8_t number;
 
 
-int main() {
+int main() {   
+    
+    time_t t;
     
+    /* Setup TD120x */
+    wait(3);
+    modem_setup();
+    
+    /* Turn off all LED */
     LED_0 = 1;
     LED_1 = 1;
     LED_2 = 1;
     LED_3 = 1;
-
-    unsigned char ID=0;
-    unsigned int  AmbiValue=0;
     
-       // print information on screen
-    pc.printf("\n\n VCNL4010 Proximity/Ambient Light Sensor");
-    pc.printf("\n Read Ambillight on demand in endless loop");
-
-    VCNL40x0_Device.ReadID (&ID);                           // Read VCNL40x0 product ID revision register
-    pc.printf("\n\n Product ID Revision Register: %d", ID);
-
-    wait_ms(3000);                                          // wait 3s (only for display)
+    /* Setup button interrupts */    
+    SW1.fall(&sw1interrupt);
+    SW2.fall(&sw2interrupt); 
+    
+    /* Intializes random number generator */
+    srand((unsigned) time(&t));     
     
     while(1) { 
-        VCNL40x0_Device.ReadAmbiOnDemand (&AmbiValue);      // read ambi value on demand
-        pc.printf("Ambient light: %5.0i cts \tIlluminance: %7.2f lx\r", AmbiValue, AmbiValue/4.0);
-        if(AmbiValue < 5000) LED_3 = 0;
-        else LED_3 = 1;
-        if(AmbiValue < 4000) LED_2 = 0;
-        else LED_2 = 1;
-        if(AmbiValue < 3000) LED_1 = 0;
-        else LED_1 = 1;
-        if(AmbiValue < 2000) LED_0 = 0;
-        else LED_0 = 1;
+        
+        if(dice1 == true && dice2 == true){
+            number = dice1val + dice2val;
+            pc.printf("\nThe number is: %d\n\r", number);            
+            
+            switch(number) {
+                case 2  :
+                    LED_0 = 1;
+                    LED_1 = 1;
+                    LED_2 = 0;
+                    LED_3 = 1;
+                    break; 
+                case 3  :
+                    LED_0 = 1;
+                    LED_1 = 1;
+                    LED_2 = 0;
+                    LED_3 = 0;
+                    break;
+                case 4  :
+                    LED_0 = 1;
+                    LED_1 = 0;
+                    LED_2 = 1;
+                    LED_3 = 1;
+                    break; 
+                case 5  :
+                    LED_0 = 1;
+                    LED_1 = 0;
+                    LED_2 = 1;
+                    LED_3 = 0;
+                    break; 
+                case 6  :
+                    LED_0 = 1;
+                    LED_1 = 0;
+                    LED_2 = 0;
+                    LED_3 = 1;
+                    break; 
+                case 7 :
+                    LED_0 = 1;
+                    LED_1 = 0;
+                    LED_2 = 0;
+                    LED_3 = 0;
+                    break; 
+                case 8  :
+                    LED_0 = 0;
+                    LED_1 = 1;
+                    LED_2 = 1;
+                    LED_3 = 1;
+                    break;
+                case 9  :
+                    LED_0 = 0;
+                    LED_1 = 1;
+                    LED_2 = 1;
+                    LED_3 = 0;
+                    break; 
+                case 10 :
+                    LED_0 = 0;
+                    LED_1 = 1;
+                    LED_2 = 0;
+                    LED_3 = 1;
+                    break; 
+                case 11  :
+                    LED_0 = 0;
+                    LED_1 = 1;
+                    LED_2 = 0;
+                    LED_3 = 0;
+                    break;  
+                case 12  :
+                    LED_0 = 0;
+                    LED_1 = 0;
+                    LED_2 = 1;
+                    LED_3 = 1;
+                    break;                
+                default : 
+                    pc.printf("\nImpossible number!!\n\r");
+                    LED_0 = 1;
+                    LED_1 = 1;
+                    LED_2 = 1;
+                    LED_3 = 1;
+            }
+            char command[SER_BUFFER_SIZE];
+            sprintf(command, "AT$SF=04%04x,2,0\n", (int) number );
+            pc.printf("Sending thrown number =  %i over Sigfox using modem command: %s\n", number , command);
+            modem_command_check_ok(command);
+            //wait_ms(5000);
+            LED_0 = 1;
+            LED_1 = 1;
+            LED_2 = 1;
+            LED_3 = 1;
+            dice1 = false;
+            dice2 = false;
+        }        
+        
     }
-}
\ No newline at end of file
+}
+void modem_setup()
+{
+    /* Reset to factory defaults */
+    if(modem_command_check_ok("AT&F")) 
+    {
+        pc.printf("Factory reset succesfull\r\n");
+    }
+    else 
+    {
+        pc.printf("Factory reset TD120x failed\r\n");
+    }
+    /* Disable local echo */
+    modem.printf("ATE0\n");
+    if(modem_command_check_ok("ATE0")) 
+    {
+        pc.printf("Local echo disabled\r\n");
+    }
+    /* Write to mem */
+    if(modem_command_check_ok("AT&W")) 
+    {
+        pc.printf("Settings saved!\r\n");
+    }    
+}
+
+bool modem_command_check_ok(char * command)
+{
+    /* first clear serial data buffers */
+    while(modem.readable()) modem.getc();
+    /* Timeout for response of the modem */
+    Timeout tmout;
+    ser_timeout = false;
+    /* Buffer for incoming data */
+    char responsebuffer[6];
+    /* Flag to set when we get 'OK' response */
+    bool ok = false;
+    bool error = false;
+    /* Print command to TD120x */
+    modem.printf(command);
+    /* Newline to activate command */
+    modem.printf("\n");
+    /* Wait untill serial feedback, min 7 seconds before timeout */
+    tmout.attach(&sertmout, 7.0);
+    while(!modem.readable()&& ser_timeout == false);
+    while(!ok && !ser_timeout && !error) 
+    {
+        if(modem.readable()) 
+        {
+            for(int i = 0; i < 5; i++)
+            {
+                responsebuffer[i] = responsebuffer[i+1];
+            }
+            responsebuffer[5] = modem.getc();
+            if(responsebuffer[0] == '\r' && responsebuffer[1] == '\n' && responsebuffer[2] == 'O' && responsebuffer[3] == 'K' && responsebuffer[4] == '\r' && responsebuffer[5] == '\n' ) 
+            {
+                ok = true;
+            }
+            else if(responsebuffer[0] == '\r' && responsebuffer[1] == '\n' && responsebuffer[2] == 'E' && responsebuffer[3] == 'R' && responsebuffer[4] == 'R' && responsebuffer[5] == 'O' ) 
+            {
+                error = true;
+            }
+        }
+    }
+    tmout.detach();
+    return ok;
+}
+/* Button 1 ISR */
+void sw1interrupt()
+{
+    if(dice1 == false){
+        pc.printf("\nDice 1 has been thrown\n\r");
+        dice1 =  true; 
+        dice1val = (rand() % 6)+1; 
+    }
+    else{
+        pc.printf("\nDice 1 has already been thrown\n\r");
+    }
+         
+}
+
+/* Button 2 ISR */
+void sw2interrupt()
+{
+    if(dice2 == false){
+        pc.printf("\nDice 2 has been thrown\n\r");
+        dice2 =  true; 
+        dice2val = (rand() % 6)+1; 
+    }
+    else{
+        pc.printf("\nDice 2 has already been thrown\n\r");
+    }
+}
+
+/* ISR for serial timeout */
+void sertmout()
+{
+    ser_timeout = true;
+}
+
+
+
diff -r 6c17d1a79f75 -r 00a17f5a247c mbed.bld
--- a/mbed.bld	Thu Nov 05 09:40:10 2015 +0000
+++ b/mbed.bld	Tue Dec 13 16:52:23 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/d75b3fe1f5cb
\ No newline at end of file