There are two parts of the code from Arduino and processing.
Arduino(about load cell)
//————————————————————————————-
// HX711_ADC.h
// Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales
// Olav Kallhovd sept2017
// Tested with : HX711 asian module on channel A and YZC-133 3kg load cell
// Tested with MCU : Arduino Nano
//————————————————————————————-
// This is an example sketch on how to use this library
// Settling time (number of samples) and data filtering can be adjusted in the HX711_ADC.h file
#include <HX711_ADC.h>
//HX711 constructor (dout pin, sck pin)
HX711_ADC LoadCell(4, 5);
long t; void setup() {
Serial.begin(9600);
Serial.println(“Wait…”);
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
LoadCell.setCalFactor(696.0); // user set calibration factor (float)
Serial.println(“Startup + tare is complete”);
}
void loop() {
//update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
//longer delay in scetch will reduce effective sample rate (be carefull with delay() in loop)
LoadCell.update();
//get smoothed value from data set + current calibration factor
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print(“Load_cell output val: “);
Serial.println(i);
t = millis();
}
//receive from serial terminal
if (Serial.available() > 0) {
float i;
char inByte = Serial.read();
if (inByte == ‘t’) LoadCell.tareNoDelay();
}
//check if last tare operation is complete
if (LoadCell.getTareStatus() == true) {
Serial.println(“Tare complete”);
}
}
Processing(about sound effect according to different ranges of weight)
import processing.serial.*;
import processing.sound.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player1;
AudioPlayer player2;
AudioPlayer player3;
Serial myPort; // The serial port
PFont myFont; // The display font
String inString; // Input string from serial port
int lf = 10; // ASCII linefeed
void setup() {
size(400, 200);
// You’ll need to make this font with the Create Font Tool
//myFont = loadFont(“ArialMS-18.vlw”);
//textFont(myFont, 18);
// List all the available serial ports:
printArray(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you’re using.
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil(lf);
minim = new Minim(this);
player1 = minim.loadFile(“Clapping.mp3”);
player2 = minim.loadFile(“oh!FatGuy.mp3”);
player3 = minim.loadFile(“nuclear-warning.mp3”);
}
void draw() {
background(0);
if (float(inString) > 1246 && float(inString) < 2076.9 ) {
if (!player1.isPlaying() ) {
player1.loop();
player2.pause();
player3.pause();
}
}
else if (float(inString)> 2118.4 && float(inString)< 2700) {
if (!player2.isPlaying() ) {
player2.loop();
player1.pause();
player3.pause();
}
}
else if (float(inString) > 2741.5) {
if (!player3.isPlaying() ) {
player3.loop();
player1.pause();
player2.pause();
}
}
else {
player3.pause();
player1.pause();
player2.pause();
}
text(“received: ” + inString, 10, 50);
}
void serialEvent(Serial p) {
inString = p.readString();
}
*player1 is mp3 clip for players weighted in 30kg – 50kg
player2 is mp3 clip for players weighted in 51kg – 65kg
player3 is mp3 clip for players weighted over 65kg
Reference :
https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing/all