Hello to you all!
So I'm working on a project that isn't exactly useful to anybody but is just a really interesting way to create and display simple binary data.
I have created what I call a 'Laser Binary Writer' or LBW. Essentially it is just a laser module pointing to a photoresistor. The Arduino takes in data from the photoresistor to generate either a 0 or a 1. If the photoresistor is receiving light from the laser, it generates a 1, and if not, a 0. It takes these 0s and 1s and places them in a string array, which gets sent to Processing. Processing then analyses the binary data and outputs the equivalent character from the ASCII table and saves it to a file. Sending multiple lines of data allows for a word or a sentence to be written and saved to a file, all from creating simple 0s and 1s from a laser and photoresistor!
I'm wanting to take this quite a few steps further, but here's the Arduino code with the Processing code below. I've also attached some pictures of the setup for your reference if you'd like to recreate this.
Arduino code:
/*
Laser Binary Writer
[IF YOU COPY AND PASTE, ENSURE TO SEPARATE COMMENTS FROM CODE]
This sketch allows you to record binary data to be sent to Processing.
A Laser Binary Writer setup is used to create the data.
The LBW takes in a photoresistor sensor value which changes depending
on whether a laser module facing it is lit or not. It then records
a value of either 1 (laser on) or 0 (laser off) in a string. When
the user creates a string of 8 1s or 0s it can be sent to Processing
which will analyse the string and output the character equivalent
from the ASCII table into a newly created file and saves it to the
sketch folder. When this file is opened in a text editor the ASCII
characters produced by the binary data will be there.
The LBW has four buttons - 'Record', 'Run', 'Laser' and 'Clear'.
Firstly, 'Laser' should be used to turn the laser on and off, which
will allow the computer to calculate whether it will record either
a 1 or a 0.
Secondly, the 'Record' button should be used to actually record
a 0 or a 1 to a string array. If the laser is on, it will record
a 1, and if the laser is off it will record a 0. This will pile up.
The 'Laser' and 'Record' buttons should be used eight times to create
a whole piece of information. For example, to get an 'A' from Processing,
you should write 01000001.
Lastly, the 'Run' button should be used to take all the piled
0s and 1s and write them to the Serial buffer as one unit.
The 'Clear' button will just clear the string array of all information.
Created Tuesday 28th March, 2017
By Steven Ryall <steven_j_ryall@hotmail.co.uk>
THIS CODE IS IN THE PUBLIC DOMAIN
*************ISSUES (1)***************
* Sometimes the 8 bits come through *
* split on the Processing side. I *
* don't know which side it could be *
* resolved on or whether it's both. *
**************************************
*/
/* Photo resistor sensor */
int sensorPin = A5;
/* Debug LED to show whether we're sending a 1 or a 0 */
int debugPin = 6;
/* Variable to store the value coming from the photoresistor */
int sensorValue = 100;
/* Laser module */
int laserPin = 2;
/* Three buttons to record data, turn the laser on and off
and to send the data to processing */
const int _recButton = 3;
const int _laserButton = 4;
const int _runButton = 5;
/* Button to clear already saved information */
const int _clearButton = 7;
/* Variable to count saved data */
int moreElements = 0;
/* String array to contain the data */
String _actions[100]{};
/* Boolean variables which correspond to buttons */
boolean _0Value, _1Value, _rec, _run, _laser;
void setup() {
/* Declare variable functions and begin Serial */
pinMode(_recButton, INPUT_PULLUP);
pinMode(_laserButton, INPUT_PULLUP);
pinMode(_runButton,INPUT_PULLUP);
pinMode(_clearButton,INPUT_PULLUP);
pinMode(debugPin,OUTPUT);
pinMode(laserPin, OUTPUT);
digitalWrite(laserPin,HIGH);
pinMode(debugPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
/* Ensure two booleans are on or off depending on
whether the laser is lit or not */
if(analogRead(sensorPin) > sensorValue ){
_0Value = true;
_1Value = false;
} else if(analogRead(sensorPin) < sensorValue){
_1Value = true;
_0Value = false;
}
/* Activate record function with button */
if (digitalRead(_recButton)==LOW){
Record();
delay(100);
}
/* Turn the laser on or off with button */
if(digitalRead(_laserButton)==LOW){
_laser = !_laser;
delay(300);
}
/* Send saved information to processing with button */
if(digitalRead(_runButton) == LOW){
Run();
}
/* Clear already saved information */
if(digitalRead(_clearButton) == LOW){
Clear();
}
/* Controlling whether or not the laser is on
depending on boolean */
if(_laser){
digitalWrite(laserPin,HIGH);
} else if(!_laser){
digitalWrite(laserPin,LOW);
}
/* Function for debug led */
if(analogRead(sensorPin) > sensorValue ){
digitalWrite(debugPin,HIGH);
} else if(analogRead(sensorPin) < sensorValue){
digitalWrite(debugPin,LOW);
}
}
/* Run function - sends each saved elements as a string
to be picked up and processed by processing */
void Run(){
for(int i=0; i<moreElements;i++){
Serial.print(_actions[i]);
}
delay(500);
Continued below...