Skip to content
Snippets Groups Projects
Commit 40e24a04 authored by Dan Stone's avatar Dan Stone
Browse files

d

parent 1b0846e1
No related branches found
No related tags found
No related merge requests found
Pipeline #393065 passed
......@@ -17,7 +17,7 @@ float inByte = 0;
void setup () {
// set the window size:
size(400, 300);
size(1400, 1300);
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
......@@ -26,7 +26,7 @@ void setup () {
// I know that the first port in the serial list on my Mac is always my
// Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, "COM23", 9600); // for Windows
myPort = new Serial(this, "COM13", 9600); // for Windows
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
......
// Graphing sketch
// This program takes ASCII-encoded strings from the serial port at 9600 baud
// and graphs them. It expects values in the range 0 to 1023, followed by a
// newline, or newline and carriage return
// created 20 Apr 2005
// updated 24 Nov 2015
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float inByte = 0;
void setup () {
// set the window size:
size(1400, 1300);
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my Mac is always my
// Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, "COM13", 9600); // for Windows
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set initial background:
background(0);
}
void draw () {
// draw the line:
loadPixels();
float n = (inByte * 10.0) / width;
float w = 16.0; // 2D space width
float h = 16.0; // 2D space height
float dx = w / width; // Increment x this amount per pixel
float dy = h / height; // Increment y this amount per pixel
float x = -w/2; // Start x at -1 * width / 2
for (int i = 0; i < width; i++) {
float y = -h/2; // Start y at -1 * height / 2
for (int j = 0; j < height; j++) {
float r = sqrt((x*x) + (y*y)); // Convert cartesian to polar
float theta = atan2(y,x); // Convert cartesian to polar
// Compute 2D polar coordinate function
float val = sin(n*cos(r) + 5 * theta); // Results in a value between -1 and 1
//float val = cos(r); // Another simple function
//float val = sin(theta); // Another simple function
// Map resulting vale to grayscale value
pixels[i+j*width] = color((val + 1.0) * 255.0/2.0); // Scale to between 0 and 255
y += dy; // Increment y
}
x += dx; // Increment x
}
updatePixels();
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
inByte = float(inString);
println(inByte);
inByte = map(inByte, 0, 1023, 0, height);
}
} // <-- missing closing brace here
# include <Servo.h>
// create a Servo object to control the ESC
Servo esc;
int potVal;
void setup() {
// initialize the serial communication:
// set the baud rate for serial communication
Serial.begin(9600);
// attach the ESC to pin 9
esc.attach(9, 1000, 2000); // the second and third parameters are the minimum and maximum pulse widths
}
void loop() {
// send the value of analog input 0:
Serial.println(analogRead(A1));
// wait a bit for the analog-to-digital converter to stabilize after the last
// reading:
delay(2);
// set the speed to half of the maximum (which is 180)
potVal = analogRead(A1); // read input from potentiometer.
int speed = map(potVal,0, 1023, 0, 180); // maps potentiometer values to PWM val
// send the speed to the ESC
esc.write(speed);
// print the speed to the serial monitor
Serial.print("Speed: ");
Serial.println(speed);
// pause for a moment before starting again
}
\ No newline at end of file
#include <Adafruit_NeoPixel.h>
int Power = 11;
int PIN = 12;
#define NUMPIXELS 1
long result; //variable for the result of the tx_rx measurement.
int analog_pin = 27; // GPIO 27 of the XIA0 RP2040
int tx_pin = 28; // GPIO 28 of the XIAO RP2040
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(tx_pin,OUTPUT); //Pin 2 provides the voltage step
Serial.begin(115200);
pixels.begin();
pinMode(Power,OUTPUT);
digitalWrite(Power, HIGH);
}
long tx_rx(){ //Function to execute rx_tx algorithm and return a value
//that depends on coupling of two electrodes.
//Value returned is a long integer.
int read_high;
int read_low;
int diff;
long int sum;
int N_samples = 100; //Number of samples to take. Larger number slows it down, but reduces scatter.
sum = 0;
for (int i = 0; i < N_samples; i++){
digitalWrite(tx_pin,HIGH); //Step the voltage high on conductor 1.
read_high = analogRead(analog_pin); //Measure response of conductor 2.
delayMicroseconds(100); //Delay to reach steady state.
digitalWrite(tx_pin,LOW); //Step the voltage to zero on conductor 1.
read_low = analogRead(analog_pin); //Measure response of conductor 2.
diff = read_high - read_low; //desired answer is the difference between high and low.
sum += diff; //Sums up N_samples of these measurements.
}
return sum;
} //End of tx_rx function.
void loop() {
result = tx_rx();
result = map(result, 17000, 23000, 0, 1024); //I recommend mapping the values of the two copper plates, it will depend on their size
Serial.println(result);
if (result < 3000) {
pixels.setPixelColor(0, pixels.Color(15, 25, 205));
} else if (result >= 5000) {
pixels.setPixelColor(0, pixels.Color(233, 242, 205));
} else {
pixels.setPixelColor(0, pixels.Color(233, 23, 23));
}
pixels.show();
delay(10);
}
# include <Servo.h>
// create a Servo object to control the ESC
Servo esc;
int potVal;
void setup() {
// set the baud rate for serial communication
Serial.begin(9600);
// attach the ESC to pin 9
esc.attach(9, 1000, 2000); // the second and third parameters are the minimum and maximum pulse widths
esc.write(0); //arm ESP
delay(1000);
}
void loop() {
// set the speed to half of the maximum (which is 180)
// send the speed to the ESC
esc.write(24);
delay(500);
esc.write(40);
delay(1000);
// print the speed to the serial monitor
// Serial.print("Speed: ");
// Serial.println(speed);
// pause for a moment before starting again
}
\ No newline at end of file
# include <Servo.h>
// create a Servo object to control the ESC
Servo esc;
int potVal;
void setup() {
// set the baud rate for serial communication
Serial.begin(9600);
// attach the ESC to pin 9
esc.attach(9, 1000, 2000); // the second and third parameters are the minimum and maximum pulse widths
int potVal;
esc.write(0); //arm ESP
delay(1000);
}
void loop() {
// set the speed to half of the maximum (which is 180)
potVal = analogRead(A1); // read input from potentiometer.
int speed = map(potVal,0, 1023, 0, 180); // maps potentiometer values to PWM val
// send the speed to the ESC
esc.write(speed);
// print the speed to the serial monitor
Serial.print("Speed: ");
Serial.println(speed);
// pause for a moment before starting again
}
\ No newline at end of file
File added
docs/images/imagW15/stepsesor.jpg

83.5 KiB

docs/images/imagW15/stepsesor2.jpg

54.4 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment