This week we take one of the NKK Smart Switches we showed you last week and make it do stuff. Making it work is pretty simple, we show you just how simple in this video.
We also take a look at the Arduino Due and Arduino Ethernet. Also, an update on the Udoo. It is shipping and mine should be here soon.
Downloads
/*######################### SMART BUTTON EXAMPLE ############################
This sketch gives a really basic example of how to send images to the Smart Button from NKK. The button
is just a basic button but the LCD screen is programmed with SPI. We use one of our smart switch boards
that uses an i2C to look for button presses and also send the control line to the smart switch. The smart
switch has a "selected" pin that needs to be high for the button to receive the data.
From: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 36 at http://tech-zen.tv
http://tech-zen.tv
For the sample code, show notes, contact information and many more
videos, visit the show page at http://tech-zen.tv/letsmakeit
Please subscribe to our YouTube channel or our netcasts at any of
your favorite netcast / podcast outlets.
We normally record Let's Make It live on Monday evenings around
9pm eastern. You can watch it live by going to tech-zen.tv and clicking
the live link at the top of the page.
We also have a community setup for our viewers and listeners. You can
join the community by going to community.tech-zen.tv.
We love input on what you would like to know or if you have an idea for
a new Let's Make it episode, you can contact us via email or phone at
the show information page.
################################################################################*/
#include <Wire.h>
#include <MCP23017.h>
#include <NKKSmartSwitch.h>
NKKSmartSwitch SmartSwitch;
// Animated logo
static uint8_t movielogo[] PROGMEM = {
32, // width
20, // height
/* page 0 (lines 0-7) */
0xfc,0xfe,0xf3,0xf3,0xff,0xff,0xf3,0xf3,0xff,0xff,0xf3,0xf3,0xff,0xff,0xf7,0xf3,
0xff,0xff,0xf7,0xf3,0xf7,0xff,0xff,0xf3,0xf3,0xfe,0xfc,0x80,0x80,0xc0,0xc0,0xc0,
/* page 1 (lines 8-15) */
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1f,0x1f,0x3f,0x3f,0x7f,
/* page 2 (lines 16-23) */
0x3,0x7,0xc,0xc,0xf,0xf,0xc,0xc,0xf,0xf,0xc,0xc,0xf,0xf,0xe,0xc,
0xf,0xf,0xe,0xc,0xe,0xf,0xf,0xc,0xe,0x7,0x3,0x0,0x0,0x0,0x0,0x0,
};
void setup() {
// Start the Serial (debugging) and UDP:
Serial.begin(9600);
// Always initialize Wire before starting the SmartSwitch library
Wire.begin();
// Switches on address 0:
//SmartSwitch.begin(0); // Address 0, pins 5+6 default
SmartSwitch.begin(7, 48, 49); // Address 4, pins 48+49
// Setting full brightness (range 0-7) of all buttons:
SmartSwitch.setButtonBrightness(7, BUTTON_ALL);
SmartSwitch.setButtonBrightness(7, BUTTON_ALL);
// Setting white color for all buttons:
SmartSwitch.setButtonColor(3,3,3,BUTTON_ALL);
// Clear the display (if anything is on it:)
SmartSwitch.clearScreen(BUTTON_ALL);
delay(500);
// Draw an image on the pixmap for button 1, centered, but offset -2 pixels in y direction (upwards). X-Y has origin in upper left corner and positive axes towards right/down
SmartSwitch.drawImage(BUTTON1, 0, -2, IMAGE_CENTER, movielogo);
SmartSwitch.updateScreen(BUTTON1); // Writes the buffered pixmap to the button.
delay(500);
// Writing a bit of text on top of the pixmap - and write to button:
SmartSwitch.writeText(BUTTON1, "TESTING", 3, TEXT_CENTER | TEXT_BACKGROUND | TEXT_REVERSE);
SmartSwitch.updateScreen(BUTTON1); // Writes the buffered pixmap to the button.
}
int i = 0;
int state, modes;
void loop() {
word buttons = SmartSwitch.buttonUpAll();
for(int j=0; j<4; j++) {
if(buttons & (1 << j)) {
modes = SmartSwitch.getButtonModes();
Serial.print("Button ");
Serial.print(j, DEC);
Serial.println(" was pressed!");
state = modes >> j*2 & B11;
Serial.print("State: ");
Serial.println(state, BIN);
if(state == 0) {
SmartSwitch.clearPixmap(1<<j);
SmartSwitch.drawLine(0,0,63,31, 1<<j);
SmartSwitch.drawLine(0,31,63,0, 1<<j);
SmartSwitch.drawHorisontalLine(0, 1<<j);
SmartSwitch.drawHorisontalLine(31, 1<<j);
SmartSwitch.drawVerticalLine(0, 1<<j);
SmartSwitch.drawVerticalLine(63, 1<<j);
SmartSwitch.updateScreen(1<<j);
SmartSwitch.setButtonModes(modes ^ 1 << 2*j);
SmartSwitch.setButtonColor(3,0,0, 1<<j);
} else if (state == 1) {
SmartSwitch.clearPixmap(1<<j);
SmartSwitch.drawCircle(31, 16, 21, 1<<j);
SmartSwitch.updateScreen(1<<j);
SmartSwitch.setButtonModes(modes ^ (state | 2) << 2*j);
SmartSwitch.setButtonColor(0,3,0, 1<<j);
} else {
SmartSwitch.clearPixmap(1<<j);
SmartSwitch.updateScreen(1<<j);
SmartSwitch.setButtonModes(modes ^ state << 2*j);
SmartSwitch.setButtonColor(0,0,3, 1<<j);
}
Serial.print("ButtonState: ");
Serial.println(SmartSwitch.getButtonModes(), BIN);
}
}
}
void animatedBox() {
int i = 0;
int inc = 3;
while(1){
i = i + inc;
if(i+12 > 256) {
inc = -5;
} else if(i < 0) {
inc = 5;
continue;
}
SmartSwitch.clearPixmap(15);
SmartSwitch.updateScreen(15);
}
}