Eight.
As I’ve been moving forward on my mapping project, I’ve also been working on figuring out how to use Arduino again. Since I’ve last used it four or five years ago, a lot has changed. Mainly, there’s now a whole editor online, whereas before, I had to actually download the software, which would basically just open up a text box in which you could write your code. Speaking of the code - - I finally found it. It’s been quite frustrating, especially since it’s been right on my computer the entire time. Anyway, I first thought that it was uploaded onto the SD card, which it wasn’t: that just held the three sound clips that the sensors would trigger. I then remembered that it was actually on the Arduino shield itself. So, I didn’t actually need the SD card reader, I needed a USB 2.0. I got one, I hooked it all up, opened the Arduino create interface and immediately erased everything that was on my shield by uploading the empty code onto it while I though I was downloading my code into the workspace. 10/10 me!
I then did what I probably should have done a month ago, and checked in my folder for my class at the time. And there it was.
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
#include <Wire.h>
SdFat sd;
SFEMP3Shield MP3player;
int tilt_s1 = 2;
int tilt_s2 = 3;
int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int tmp102Address = 0x48;
void setup() {
Serial.begin(9600);
pinMode(tilt_s1, INPUT);
pinMode(tilt_s2, INPUT);
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
Wire.begin();
//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
//motion sensor
//start playing track 000
MP3player.playTrack(000);
}
int getTiltPosition(){
int s1 = digitalRead(tilt_s1);
int s2 = digitalRead(tilt_s2);
return (s1 << 1) | s2; //bitwise math to combine the values
}
//do something else now
void loop() {
Serial.println("I'm bored!");
delay(2000);
int position = getTiltPosition();
Serial.println(position);
delay(200); //only here to slow down the serial output
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
float celsius = getTemperature();
Serial.print("Celsius: ");
Serial.println(celsius);
float fahrenheit = (1.8 * celsius) + 32;
Serial.print("Fahrenheit: ");
Serial.println(fahrenheit);
delay(200); //just here to slow down the output. You can remove this
//soft switch
//start playing track 001
MP3player.playTrack(001);
//temp sensor
//start playing track 002
MP3player.playTrack(002);
}
float getTemperature(){
Wire.requestFrom(tmp102Address,2);
byte MSB = Wire.read();
byte LSB = Wire.read();
//it's a 12bit int, using two's compliment for negative
int TemperatureSum = ((MSB << 8) | LSB) >> 4;
float celsius = TemperatureSum*0.0625;
return celsius;
}
Now, just looking at it, I don’t remember what any of this means together. In bits, it makes sense. I think. It’s interesting, as we’ve talked about before, the sheer number of documents and links and codes and parts of codes that are leftover from this project: working digitally creates lots of stuff. And it’s quite overwhelming. In fact, doing this has been as much making an archive as trying to understand my archive from 5 years ago. Whatever logic I implemented then, just doesn’t make sense to me now even though it’s on the same computer, done by the same person, in a similar folder/file system I continue to use today. And I’m realizing more and more that recreating, digitally, is not just a matter of copy-paste.