Fraise  2.1
FRAmework for Interfacing Software and Electronics
Switch module

Automates the use of digital input pins. More...

Automates the use of digital input pins.

Example :

/*********************************************************************
* switch example for Versa1.0
* Switch capture on connectors K1, K2, K3 and K4.
*********************************************************************/
#define BOARD Versa1
#include <fruit.h>
#include <switch.h>
t_delay mainDelay;
void setup(void) {
//----------- Setup ----------------
pinModeDigitalOut(LED); // set the LED pin mode to digital out
digitalClear(LED); // clear the LED
delayStart(mainDelay, 5000); // init the mainDelay to 5 ms
//----------- Switch setup ----------------
switchInit(); // init switch module
switchSelect(0,K1); // assign connector K1 to switch channel 0
switchSelect(1,K2);
switchSelect(2,K3);
switchSelect(3,K4);
}
void loop() {
// ---------- Main loop ------------
fraiseService(); // listen to Fraise events
switchService(); // switch management routine
if(delayFinished(mainDelay)) // when mainDelay triggers :
{
delayStart(mainDelay, 5000); // reinit the mainDelay to 5 ms
switchSend(); // send switch channels that changed
}
}
// Receiving
void fraiseReceiveChar() // receive text
{
unsigned char c;
if(c=='L'){ //switch LED on/off
digitalWrite(LED, c!='0');
}
else if(c=='E') { // echo text (send it back to host)
printf("C");
c = fraiseGetLen(); // get length of current packet
while(c--) printf("%c",fraiseGetChar());// send each received byte
putchar('\n'); // end of line
}
}

Initialization functions

void switchInit ()
 Call it once in setup()
 
#define switchSelect(num, conn)
 Select a pin for a switch channel. Assign the pin to the switch channel. More...
 

Loop functions

void switchService (void)
 Call in loop().
 
char switchSend (void)
 Call at the maximum rate you want to report switches. More...
 

Utilities

void switchDeselect (unsigned char channel)
 Deselect a channel.
 
char switchGet (unsigned char chan)
 Get the state of a channel. More...
 

Function Documentation

◆ switchSend()

char switchSend ( void  )

Call at the maximum rate you want to report switches.

Returns
Number of channels sent.

◆ switchGet()

char switchGet ( unsigned char  chan)

Get the state of a channel.

Parameters
chanChannel to read.
Returns
State of the channel.

Macro Definition Documentation

◆ switchSelect

#define switchSelect (   num,
  conn 
)

Select a pin for a switch channel. Assign the pin to the switch channel.

Parameters
numNumber of the channel (first channel = 0).
connSymbol of the pin (example : K1 for connector 1).
digitalWrite
#define digitalWrite(conn, val)
Digital write to pin. Set the pin output voltage to LOW or HIGH.
Definition: core.h:162
loop
void loop()
User defined forever loop.
fruitInit
void fruitInit(void)
Init fruit module at setup().
t_delay
unsigned long t_delay
Delay type.
Definition: core.h:215
digitalClear
#define digitalClear(conn)
Digital clear pin. Clear the pin output voltage.
Definition: core.h:168
fraiseGetLen
unsigned char fraiseGetLen()
Get total length of current receive packet.
switchInit
void switchInit()
Call it once in setup()
switchSend
char switchSend(void)
Call at the maximum rate you want to report switches.
fruit.h
switch.h
fraiseService
void fraiseService(void)
Fraise device service routine.
switchSelect
#define switchSelect(num, conn)
Select a pin for a switch channel. Assign the pin to the switch channel.
Definition: switch.h:55
setup
void setup()
User defined initialization.
fraiseGetChar
unsigned char fraiseGetChar()
Get next char from receive buffer.
pinModeDigitalOut
#define pinModeDigitalOut(conn)
Set pin mode to Digital Output.
Definition: core.h:142
delayFinished
#define delayFinished(delay)
Test delay timeout.
Definition: core.h:225
switchService
void switchService(void)
Call in loop().
delayStart
#define delayStart(delay, micros)
Start delay.
Definition: core.h:220
fraiseReceiveChar
void fraiseReceiveChar()
String message to this device.