To find out more about Team Nixie, see their work at flynixie.com or follow them on https://www.facebook.com/flynixie.
Make It Wearable Finalists | Meet Team Nixie
/*
TFT Graph
This example for an Arduino screen reads
the value of an analog sensor on A0, and
graphs the values on the screen.
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/TFTGraph
*/
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
TFT TFTscreen = TFT(cs, dc, rst);
// position of the line on screen
int xPos = 0;
void setup() {
// initialize the serial port
Serial.begin(9600);
// initialize the display
TFTscreen.begin();
// clear the screen with a pretty color
TFTscreen.background(250, 16, 200);
}
void loop() {
// read the sensor and map it to the screen height
int sensor = analogRead(A0);
int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height());
// print out the height to the serial monitor
Serial.println(drawHeight);
// draw a line in a nice color
TFTscreen.stroke(250, 180, 10);
TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height());
// if the graph has reached the screen edge
// erase the screen and start again
if (xPos >= 160) {
xPos = 0;
TFTscreen.background(250, 16, 200);
}
else {
// increment the horizontal position:
xPos++;
}
delay(16);
}
>>> from pyfirmata import Arduino, util
>>> board = Arduino('/dev/ttyACM0')
>>> board.digital[13].write(1)
>>> board.digital[13].write(0)
#include <Wire.h>
#define LED_PIN 13
byte CMD_ON = 0x00;
byte CMD_OFF = 0x01;
byte cmd = CMD_OFF;
byte slave_address = 7;
void setup()
{
// Start I2C Bus as Master
Wire.begin();
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
}
void loop()
{
if(cmd == CMD_OFF){
delay(500);
cmd = CMD_ON; //prepare next cmd
}else{
delay(1500);
cmd = CMD_OFF; //prepare next cmd
}
Wire.beginTransmission(slave_address);
Wire.write(cmd);
Wire.endTransmission();
}
#include <Wire.h>
#define LED_PIN 13
//7-bit slave address (optional)
byte slave_address = 7;
byte CMD_ON = 0x00;
byte CMD_OFF = 0x01;
void setup() {
// Start I2C Bus as Slave
Wire.begin(slave_address);
Wire.onReceive(receiveEvent);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
}
void loop() {
}
void receiveEvent(int howMany) {
byte cmd = Wire.read();
if (cmd == CMD_ON){
digitalWrite(LED_PIN, HIGH);
}else if(cmd == CMD_OFF){
digitalWrite(LED_PIN, LOW);
}
}
#include <SPI.h>
byte dataOut;
byte dataIn;
int pinSS = 10; //Slave Select, active LOW
void setup(){
Serial.begin(115200); //link to PC
pinMode(pinSS, OUTPUT);
digitalWrite(pinSS, HIGH);
SPI.begin();
}
void loop(){
while(Serial.available() > 0){
dataOut = Serial.read();
dataIn = spiWriteAndRead(dataOut);
Serial.write(dataIn);
}
}
byte spiWriteAndRead(byte dout){
byte din;
digitalWrite(pinSS, LOW);
delay(1);
din = SPI.transfer(dout);
digitalWrite(pinSS, HIGH);
return din;
}
byte dataEcho; //echo back input data in next round
byte dataToPC; //send input data to PC
void setup() {
Serial.begin(115200); //link to PC
//The Port B Data Direction Register
DDRB |= 0b00010000;
//The Port B
PORTB |= 0b00000100;
//SPI Control Register
SPCR |= 0b11000000;
//SPI status register
SPSR |= 0b00000000;
dataEcho = 0;
dataToPC = 0;
sei();
}
void loop() {
if(dataToPC != 0){
Serial.write(dataToPC);
dataToPC = 0;
}
}
ISR(SPI_STC_vect){
cli();
//while SS Low
while(!(PINB & 0b00000100)){
SPDR = dataEcho;
//wait SPI transfer complete
while(!(SPSR & (1 << SPIF)));
dataEcho = SPDR; //send back in next round
}
sei();
}
// 2-dimensional array of row pin numbers:
const int row[8] = {
2, 7, 19, 5, 13, 18, 12, 16
};
// 2-dimensional array of column pin numbers:
const int col[8] = {
6, 11, 10, 3, 17, 4, 8, 9
};
// 2-dimensional array of pixels:
int pixels[8][8];
int posX = 7;
int posY = 7;
int count = 30;
bool bg = false;
unsigned int timer1_counter;
int scanningRow = 0;
void setup() {
Serial.begin(9600);
// initialize the I/O pins as outputs
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisPin], HIGH);
}
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
//timer1_counter for 1 sec, with prescaler=256
//65536 - 16000000/256
//timer1_counter = 3036;
//timer1_counter for 0.5 sec, with prescaler=256
//65536 - 16000000/(256*2)
//timer1_counter = 34286;
//timer1_counter for 0.1 sec, with prescaler=256
//65536 - 16000000/(256*10)
//timer1_counter = 59286;
//timer1_counter for 0.001 sec, with prescaler=256
//65536 - 16000000/(256*100)
//timer1_counter = 64911;
//timer1_counter for 0.0002 sec, with prescaler=256
//65536 - 16000000/(256*500)
timer1_counter = 65411;
TCNT1 = timer1_counter; // preload timer
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
//init pixels
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
for (int x = 4; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = LOW;
}
}
pixels[1][3] = LOW;
}
ISR(TIMER1_OVF_vect) // interrupt service routine
{
TCNT1 = timer1_counter; // preload timer
//scan LED Matrix in ISR
digitalWrite(row[scanningRow], LOW);
if(++scanningRow>=8){
scanningRow = 0;
}
for (int thisCol = 0; thisCol < 8; thisCol++) {
int thisPixel = pixels[scanningRow][thisCol];
digitalWrite(col[thisCol], thisPixel);
}
digitalWrite(row[scanningRow], HIGH);
}
void loop() {
//refreshScreen();
//Do something, block the loop
Serial.println("Hello!");
//Serial.println("Hello! again");
}
void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}
}
// 2-dimensional array of row pin numbers:
const int row[8] = {
2, 7, 19, 5, 13, 18, 12, 16
};
// 2-dimensional array of column pin numbers:
const int col[8] = {
6, 11, 10, 3, 17, 4, 8, 9
};
// 2-dimensional array of pixels:
int pixels[8][8];
int posX = 7;
int posY = 7;
int count = 30;
bool bg = false;
volatile unsigned long lasttime;
volatile unsigned long now;
int timer1_counter;
void setup() {
Serial.begin(9600);
// initialize the I/O pins as outputs
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisPin], HIGH);
}
setupScreen();
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
//timer1_counter for 1 sec, with prescaler=256
//65536 - 16000000/256
//timer1_counter = 3036;
//timer1_counter for 0.5 sec, with prescaler=256
//65536 - 16000000/(256*2)
//timer1_counter = 34286;
//timer1_counter for 0.1 sec, with prescaler=256
//65536 - 16000000/(256*10)
timer1_counter = 59286;
TCNT1 = timer1_counter; // preload timer
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
lasttime = millis();
}
ISR(TIMER1_OVF_vect) // interrupt service routine
{
TCNT1 = timer1_counter; // preload timer
if(posX--==0){
posX = 7;
if(posY--==0){
posY = 7;
bg = !bg;
}
}
setupScreen();
now = millis();
Serial.println(now - lasttime);
lasttime = now;
}
void loop() {
refreshScreen();
}
void setupScreen(){
if(bg){
//ON all others
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = LOW;
}
}
//OFF current pos
pixels[posX][posY] = HIGH;
}else{
//OFF all others
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
//ON current pos
pixels[posX][posY] = LOW;
}
}
void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}
}
//To install 'serialport' locally, enter the command:
//$ npm install serialport
//Otherwise, Error: Cannot find module 'serialport' will reported
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort('/dev/ttyACM0',
{ baudrate: 9600
});
serialPort.on("open", function () {
console.log('open');
setTimeout(function() {
serialPort.write("Hello...", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
setTimeout(function() {
serialPort.write("...from Node.js", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
}, 1000);
}, 3000);
});