Commit ac3ed21c authored by Philip Hozier's avatar Philip Hozier
Browse files

week14 10/5 update #2

parent ccab76d9
......@@ -12,7 +12,13 @@ draft: false
---
# Interface & Application Programming
![Workflow - Sketch](../week1/workflow-800px67.jpg "Workflow - Sketch")
{{< rawhtml >}}
<figure class="video_container">
<video controls="true" width="100%" allowfullscreen="true" poster="../week14/week14-hero-thumbnail.jpg">
<source src="../week14/week14-hero.mp4" type="video/mp4">
</video>
</figure>
{{< /rawhtml >}}
---
## Summary
......@@ -48,7 +54,6 @@ Compare as many tool options as possible.
### What we did
---
As a group we were a little overwhelmed by the amount of languages and 'tools' there were that were capable of connecting with the serial port of the computer. [Nadieh](http://fabacademy.org/2021/labs/waag/students/nadieh-bremer/ "Nadieh Bremer") visualises her data professionally with [D3](https://d3js.org/ "D3"). She offered to give a little impromptu presentation of this framework and how it connects to data sources and can be used as a application interface.
D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.
......@@ -130,7 +135,7 @@ Visiting the 'localhost' address in your browser should now show a list of the f
---
## Individual Assignment
![Individual Assignment](../week4/individual-assignment.jpg "my FDTI")
![Individual Assignment](../week14/week14-hero-thumbnail.jpg "my interface")
Write an application that interfaces a user with an input &/or output device that you made.
......@@ -249,6 +254,8 @@ In the '<body>' section make a call to your javascript file.
### The interface
To keep it as simple as possible, and use the 3 points of data that the sensor send out, I decided to map the output to an RGB value of the background of a webpage. As the user would interact with the sensor it would change the colour of the page background.
To get to data points of between 0 and 255 from the sensor meant i would have to do a little bit of manipulation to the data first before it can be sent to the web browser. This was easiest to do in the IC, and send correct data to the p5 server where there wouldn't need any other manipulation in javascript.
......@@ -316,4 +323,9 @@ It was pushing out expected serial values from which i could work with :).
---
## FILES
---
\ No newline at end of file
---
| **FILE** | **DESCRIPTION** |
|---|----|
| [Javascript+HTML](../week14/week14-scripts.zip "Javascript+HTML") | The Javascript + HTML files. |
| [Arduino sketch](../week14/wk14-3axis-output.ino "Arduino sketch") | The Arduino sketch. |
#include <Wire.h>
//my stuff
////// OUTPUTS
#define LED1_pin A5
#define LED2_pin A6
/////// INPUT
#define BTN_pin A7
//////////////
#define BUFFER_SIZE 25
#define ADXL343_ADDRESS (0x53) // I2C ADXL343 ALT Address
#define ADXL343_REG_DATAX0 (0x32) // X-axis data 0
#define ADXL343_REG_DATAY0 (0x34) // Y-axis data 0
#define ADXL343_REG_DATAZ0 (0x36) // Z-axis data 0
int i = 0;
int pb3, pb4;
char buffer[10];
uint8_t adxl343WriteRegister(uint8_t reg, uint8_t value) {
Wire.beginTransmission(ADXL343_ADDRESS);
Wire.write((uint8_t)reg);
Wire.write((uint8_t)value);
Wire.endTransmission();
}
uint8_t adxl343ReadRegister(uint8_t reg) {
Wire.beginTransmission(ADXL343_ADDRESS);
Wire.write((uint8_t)reg);
Wire.endTransmission();
Wire.requestFrom(ADXL343_ADDRESS, 1);
return Wire.read();
}
int16_t adxl343ReadWord(uint8_t reg) {
Wire.beginTransmission(ADXL343_ADDRESS);
Wire.write((uint8_t)reg);
Wire.endTransmission();
Wire.requestFrom(ADXL343_ADDRESS, 2);
return (uint16_t)(Wire.read() | (Wire.read() << 8));
}
void setup() {
//// mystuff
// INPUT
pinMode(BTN_pin, INPUT_PULLUP);
// OUPUTS
pinMode(LED1_pin, OUTPUT);
pinMode(LED2_pin, OUTPUT);
/////////////////
delay(2000);
Serial.begin(9600);
//// mystuff
while (!Serial);
//////////////
Serial.flush();
//Serial.print("hello_serial: starting\n");
Wire.begin();
//mystuff - feedback setup done
Blink(LED1_pin);
Blink(LED2_pin);
/////////////////
uint8_t deviceId = adxl343ReadRegister(0x00);
//Serial.print(" deviceId: ");
//Serial.println(deviceId);
adxl343WriteRegister(0x2D, 0x08); // POWER_CTL register
adxl343WriteRegister(0x31, 0x08); // Full res register
i = 0;
}
void loop() {
//_delay_ms(500);
delay(50);
i++;
int16_t x = adxl343ReadWord(ADXL343_REG_DATAX0);
int16_t y = adxl343ReadWord(ADXL343_REG_DATAY0);
int16_t z = adxl343ReadWord(ADXL343_REG_DATAZ0);
// try to convert numbers into range of 0-255 for RGB
// send numbers to serial.
// need int16_t below ???
// reverse numbers
if (x <= 0) {
x = x * -1;
}
if (y <= 0) {
y = y * -1;
}
if (z <= 0) {
z = z * -1;
}
int minValue = 0;
int maxValue = 320;
//
x = map(x, minValue, maxValue, 0, 255);
y = map(y, minValue, maxValue, 0, 255);
z = map(z, minValue, maxValue, 0, 255);
//
//Serial.print("x: ");
Serial.print(x);
//Serial.print("\ty: ");
Serial.print(",");
Serial.print(y);
//Serial.print("\tz: ");
Serial.print(",");
Serial.print(z);
Serial.println(",");
///mystuff - feedback sending value
Blink(LED1_pin);
}
// mystuff
/////////// Blink //////////
void Blink(int whichLED) {
digitalWrite(whichLED, HIGH);
delay(100);
digitalWrite(whichLED, LOW);
}
/////////
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment