Skip to content

Instantly share code, notes, and snippets.

Created November 5, 2017 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/001c11f9992647b696982dfbdf6445da to your computer and use it in GitHub Desktop.
Save anonymous/001c11f9992647b696982dfbdf6445da to your computer and use it in GitHub Desktop.
ANTglobe
#include <Boards.h>
#include <Firmata.h>
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_14 = CapacitiveSensor(4,14);
CapacitiveSensor cs_4_15 = CapacitiveSensor(4,15);
CapacitiveSensor cs_4_16 = CapacitiveSensor(4,16);
CapacitiveSensor cs_4_17 = CapacitiveSensor(4,17);
CapacitiveSensor cs_4_18 = CapacitiveSensor(4,18);
CapacitiveSensor cs_4_19 = CapacitiveSensor(4,19);
int isTouched1 = 0;
int isTouched2 = 0;
int isTouched3 = 0;
int isTouched4 = 0;
int isTouched5 = 0;
int isTouched6 = 0;
int threshold = 80;
void setup() {
// Initiate Serial Communication
Serial.begin(57600);
// make time out lower for parseInt function
Serial.setTimeout(10);
}
void loop() {
// check if we have incoming data on our serialport
while(Serial.available() > 0) {
// check if we have an empty string
// we use this as a trigger to send our sensor data to Processing
// Serial.peek doesn't remove a character from the buffer
if (Serial.peek() == '\n') {
// empty the buffer
while( Serial.read() != -1 );
sendData();
}
}
}
void sendData() {
long total1 = cs_4_14.capacitiveSensor(30);
long total2 = cs_4_15.capacitiveSensor(30);
long total3 = cs_4_16.capacitiveSensor(30);
long total4 = cs_4_17.capacitiveSensor(30);
long total5 = cs_4_18.capacitiveSensor(30);
long total6 = cs_4_19.capacitiveSensor(30);
if(total1 > threshold) isTouched1 = 1;
else isTouched1 = 0;
if(total2 > threshold) isTouched2 = 1;
else isTouched2 = 0;
if(total3 > threshold) isTouched3 = 1;
else isTouched3 = 0;
if(total4 > threshold) isTouched4 = 1;
else isTouched4 = 0;
if(total5> threshold) isTouched5 = 1;
else isTouched5 = 0;
if(total6> threshold) isTouched6 = 1;
else isTouched6 = 0;
Serial.print(isTouched1);
Serial.print(",");
Serial.print(isTouched2);
Serial.print(",");
Serial.print(isTouched3);
Serial.print(",");
Serial.print(isTouched4);
Serial.print(",");
Serial.print(isTouched5);
Serial.print(",");
Serial.println(isTouched6);
/* Serial.print(total1);
Serial.print(",");
Serial.print(total2);
Serial.print(",");
Serial.print(total3);
Serial.print(",");
Serial.print(total4);
Serial.print(",");
Serial.print(total5);
Serial.print(",");
Serial.println(total6); */
// always end with a newline/carriage return
// our Processing code looks for this before processing the data.
//Serial.println();
}
// Code by: Roos M Jansen
// www.roosjansen.com
//sound ------------------------------------------------------------------------------------------------
import ddf.minim.*;
Minim minim;
final int DOKEY = 0;
final int REKEY = 1;
final int MIKEY = 2;
final int FAKEY = 3;
final int SOKEY = 4;
final int LAKEY = 5;
AudioPlayer song[] = new AudioPlayer[6];
//images ----------------------------------------------------------------------------------------------
PImage img_background;
PImage img_pick;
//foreground image country
int imageIndex = 0; //initial image to be displayed is the first
PImage[] countries = new PImage[6];
//background image country
int imageIndexBackground = 0; //initial image to be displayed is the first
PImage[] countriesBackground = new PImage[6];
//float transparency = 0;
// Serial library. -----------------------------------------------------------------------------------
import processing.serial.*;
// although we can work with bytes we use strings to keep everything human readable
// Serial port object
Serial serialPort;
// to store values received from the input.
// modify the length for the amount of values you expect to receive.
int [] incomingValues = new int[6];
int [] lastIncomingValues = new int[6];
// ---------------------------------------------------------------------------------------------------
void setup() {
size(1080, 720);
frameRate(25);
minim = new Minim(this);
song[DOKEY] = minim.loadFile("DO.wav", 2048);
song[REKEY] = minim.loadFile("RE.wav", 2048);
song[MIKEY] = minim.loadFile("MI.wav", 512);
song[FAKEY] = minim.loadFile("FA.wav", 512);
song[SOKEY] = minim.loadFile("SO.wav", 512);
song[LAKEY] = minim.loadFile("LA.wav", 512);
// Images ------------------------------------------------------------------------------------------
img_background = loadImage("background.JPG");
img_pick = loadImage("pick-country.png");
image(img_background,0,0,1080,720);
image(img_pick,150,140,780,440);
//Foreground Images
countries[0] = loadImage("iceland.png");
countries[1] = loadImage("brasil.png");
countries[2] = loadImage("netherlands.png");
countries[3] = loadImage("malta.png");
countries[4] = loadImage("indonesia.png");
countries[5] = loadImage("japan.png");
//Background Images
countriesBackground[0] = loadImage("icelandBackground.JPG");
countriesBackground[1] = loadImage("brasilBackground.jpg");
countriesBackground[2] = loadImage("netherlandsBackground.jpg");
countriesBackground[3] = loadImage("maltaBackground.jpg");
countriesBackground[4] = loadImage("indonesiaBackground.jpg");
countriesBackground[5] = loadImage("japanBackground.jpg");
//Arduino connectivity
printArray(Serial.list());
String portName = Serial.list()[0];
serialPort = new Serial(this, portName, 57600);
serialPort.clear();
serialPort.bufferUntil(10);
}
//-------------------------------------------------------------------------------------------------
void draw() {
// Incoming Values
for(int i = 0; i<incomingValues.length; i++) {
if(incomingValues[i] != lastIncomingValues[i]) {
if(incomingValues[i] == 1) {
// println(song[i]);
if(song[i].isPlaying() == false){
song[i].rewind();
song[i].play();
showImage(i);
}
else{
song[i].pause();
}
}
} lastIncomingValues[i] = incomingValues[i];
}
String outgoingData = "\n";
serialPort.write(outgoingData);
}
// Functions -------------------------------------------------------------------------------------
void showImage(int i) {
image(countriesBackground[i],0,0,1080,720);
image(countries[i],0,0,1080,720);
// transparent();
}
// Fade-in Image (Contains Bugs)------------------------------------------------------------------
//void transparent() {
// for(float j = 0; j < 255; j++) {
// transparency = j;
// background(0);
// tint(255, transparency);
// background(255);
// println(transparency);
// delay(25);
// }
//}
// Creating the Array -----------------------------------------------------------------------------
void serialEvent(Serial port) {
String incomingData = port.readStringUntil(10);
if(incomingData != null) {
incomingData = trim(incomingData);
String[] incomingString = split(incomingData, ',');
if(incomingString.length != incomingValues.length) {
println("WARNING: more or less incoming values. Change the incomingValues array size to: " + incomingString.length);
}
else {
incomingValues = int(incomingString);
//printArray(incomingValues);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment