I've been working on an LED wall and came into a RAM issue. Basically I am using teensy 3.0 and trying to load the following script, however, the script errors out with .bss will not fit into region 'RAM'
Please help! Any information would be greatly appreciated! Thanks!
/*
Nike NFL draft LED wall program
OctoWS2811 BasicTest.ino - Basic RGB LED Test
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
*/
#include <OctoWS2811.h>
const int ledsPerStrip = 290;
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
#define ORANGE 0xE05800
#define WHITE 0xFFFFFF
#define BLACK 0x000000
#define BLACK2 0x1E1E1E
void setup() {
leds.begin();
leds.show();
}
static int widths[] = { 30, 30, 50, 90, 40, 60 };
static int speeds[] = { 5, 5, 10, 16, 11, 13 };
static int locations[] = { 0, 0, 0, 0, 0, 0 };
static int counter = 0;
//static int location = 0;
static boolean reverse = false;
int blend(int source , float alpha) {
int source_r = (source >> 16);
int source_g = ((source >> 8) & 0x00FF);
int source_b = (source & 0x0000FF);
source_r = source_r * alpha;
source_g = source_g * alpha;
source_b = source_b * alpha;
return source_b | (source_g << 8) | (source_r << 16);
}
void loop() {
int microsec = 2000000 / leds.numPixels(); // change them all in 2 seconds
int location;
int offset;
int width;
int current;
int min;
int color;
float alpha = 0.95; // Set brightness of head
int head_width = 3; // Set width of head
delay(20);
int i;
for(i = 0; i < 6; ++i) {
location = locations[i];
width = widths[i];
color = 0xFFFFFF;
offset = i*ledsPerStrip;
location = location + speeds[i];
if(location > ledsPerStrip + width) {
location = 0;
}
locations[i] = location;
if(location < width) {
current = location;
min = 0;
} else if(location >= width) {
current = location;
min = location - width + 1;
}
for(current; current >= 0; --current) {
if(current >= min) {
if(current < ledsPerStrip) {
if(!reverse) {
leds.setPixel(current + offset, color);
} else {
leds.setPixel((ledsPerStrip - current) + offset, color);
}
}
if(current < (location - head_width)) {
color = blend(color, alpha);
}
} else {
if(!reverse) {
leds.setPixel(current + offset, BLACK);
} else {
leds.setPixel((ledsPerStrip - current) + offset, BLACK);
}
}
}
}
leds.show();
counter++;
}
And the returned error:
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.5 (Windows 7), Board: "Teensy 3.0"
c:/program files/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/bin/ld.exe: Nike_NFL_Program.cpp.elf section .bss' will not fit in regionRAM'
c:/program files/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/bin/ld.exe: region `RAM' overflowed by 1028 bytes
collect2.exe: error: ld returned 1 exit status
Thanks!
Your simply running out of memory. sizing it down from 6 to 5 compiles. Note that the 3.0 has 16384 of SRAM. Each multiple of consumes a large chunk of the limited 16384 of SRAM.
I think you should put the code of static or variable to DRAM.
Such as the code you supply.
From:
const int ledsPerStrip = 290;
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];
const int config = WS2811_GRB | WS2811_800kHz;
static int widths[] = { 30, 30, 50, 90, 40, 60 };
static int speeds[] = { 5, 5, 10, 16, 11, 13 };
static int locations[] = { 0, 0, 0, 0, 0, 0 };
static int counter = 0;
To:
#include "link_defs.h"
__SECTION(dram.rodata) const int ledsPerStrip = 290;
__SECTION(dram.bss) DMAMEM int displayMemory[ledsPerStrip*6];
__SECTION(dram.bss) int drawingMemory[ledsPerStrip*6];
__SECTION(dram.rodata) const int config = WS2811_GRB | WS2811_800kHz;
__SECTION(dram.data) static int widths[] = { 30, 30, 50, 90, 40, 60 };
__SECTION(dram.data) static int speeds[] = { 5, 5, 10, 16, 11, 13 };
__SECTION(dram.data) static int locations[] = { 0, 0, 0, 0, 0, 0 };
__SECTION(dram.data) static int counter = 0;
Related
I try to generate a video with a timebase more precise than the 1/fps (camera frame rate are not constant). But the generated AVI does not seem to take into account the framerate that I indicate.
#include <iostream>
extern "C" {
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
constexpr int TIMEFACTOR = 10;
static void encodeFrame(AVCodecContext *avctx, AVFormatContext *ctx, AVFrame* frame)
{
int ret = avcodec_send_frame(avctx, frame);
AVPacket packet;
av_init_packet(&packet);
ret = 0;
while (ret >= 0) {
ret = avcodec_receive_packet(avctx, &packet);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
return; // nothing to write
};
//packet.pts = (frame) ? frame->pts : packet.pts;
av_packet_rescale_ts(&packet, avctx->time_base, ctx->streams[0]->time_base);
packet.duration = TIMEFACTOR;
av_interleaved_write_frame(ctx, &packet);
av_packet_unref(&packet);
}
}
static void fill_yuv_frame(AVFrame* frame, int width, int height, int frameId)
{
// Y
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
frame->data[0][y * frame->linesize[0] + x] = x + y + frameId * 3;
}
}
// Cb and Cr
for (int y = 0; y < height / 2; y++) {
for (int x = 0; x < width / 2; x++) {
frame->data[1][y * frame->linesize[1] + x] = 128 + y + frameId * 2;
frame->data[2][y * frame->linesize[2] + x] = 64 + x + frameId * 5;
}
}
}
int main(int argc, char** argv)
{
const char filename[] = "output.avi";
const char encoder[] = "mpeg4";
constexpr int WIDTH = 640;
constexpr int HEIGHT = 480;
av_log_set_level(AV_LOG_DEBUG);
//delete file because libavcodec reload file
remove(filename);
AVFormatContext* ofmtCtx;
int ret = avformat_alloc_output_context2(&ofmtCtx, NULL, "avi", filename);
AVCodec* avcodec = avcodec_find_encoder_by_name(encoder);
AVCodecContext* avctx = avcodec_alloc_context3(avcodec);
avctx->width = WIDTH ;
avctx->height = HEIGHT ;
avctx->sample_aspect_ratio = { 1, 1 };
avctx->pix_fmt = AV_PIX_FMT_YUV420P; //Do not work with other type
avctx->codec_id = AV_CODEC_ID_MPEG4;
avctx->bit_rate = 4 * 1000 * 1000;
avctx->time_base = av_make_q(1, 25 * TIMEFACTOR);
avctx->framerate = av_make_q(25, 1);
avctx->ticks_per_frame = TIMEFACTOR;
avctx->gop_size = 10;
avctx->max_b_frames = 1;
AVStream* m_outStream = avformat_new_stream(ofmtCtx, NULL);
ret = avcodec_open2(avctx, avcodec, NULL);
ret = avcodec_parameters_from_context(m_outStream->codecpar, avctx);
m_outStream->time_base = avctx->time_base;
m_outStream->r_frame_rate = avctx->framerate;
m_outStream->avg_frame_rate = avctx->framerate;
ret = avio_open(&(ofmtCtx->pb),
filename,
AVIO_FLAG_WRITE);
ret = avformat_write_header(ofmtCtx, NULL);
av_dump_format(ofmtCtx, 0, filename, 1);
AVFrame * avframe = av_frame_alloc();
avframe->format = avctx->pix_fmt;
avframe->width = avctx->width;
avframe->height = avctx->height;
ret = av_frame_get_buffer(avframe, 0);
ret = av_frame_make_writable(avframe);
for (int i = 0; i < 25; ++i) {
fflush(stdout);
fill_yuv_frame(avframe, avctx->width, avctx->height, i);
avframe->pts = i * TIMEFACTOR;
encodeFrame(avctx, ofmtCtx, avframe);
}
encodeFrame(avctx, ofmtCtx, NULL);
av_write_trailer(ofmtCtx);
return 0;
}
And this is dump output :
[mpeg4 # 000002AA64FA1880] intra_quant_bias = 0 inter_quant_bias = -64
[file # 000002AA64F69AC0] Setting default whitelist 'file,crypto'
[avi # 000002AA64F73400] reserve_index_space:0 master_index_max_size:256
[avi # 000002AA64F73400] duration_est:36000.000, filesize_est:18.4GiB, master_index_max_size:256
Output #0, avi, to 'output.avi':
Metadata:
ISFT : Lavf58.12.100
Stream #0:0, 0, 1/250: Video: mpeg4, 1 reference frame (FMP4 / 0x34504D46), yuv420p, 640x480 (0x0) [SAR 1:1 DAR 4:3], 0/1, q=2-31, 4000 kb/s, 25 fps, 25 tbr, 250 tbn
But if I open the video in ffmpeg command line fps is 250, and video content 250 frames, with many dropframe.
So I've been making this program for our final project. It's a stopwatch and I added a ticking animation that ticks every second. The only problem I have is after I push the stop button,it doesn't go back to its original position. Here's the code :
#include "dialog.h"
#include "ui_dialog.h"
#include <QTimer>
#include <QPainter>
#include <QMessageBox>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(update()));
connect(timer,SIGNAL(timeout()),this,SLOT(tick()));
sec = 0;
sec2 = 0;
sec3 = 0;
setUpdatesEnabled(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_start_clicked()
{
timer->start(10);
}
void Dialog::on_stop_clicked()
{
sec = 0;
sec2 = 0;
sec3 = 0;
timer->stop();
ui->label->setNum(sec);
ui->label_2->setNum(sec2);
ui->label_3->setNum(sec3);
}
void Dialog::on_record_clicked()
{
if(sec == 0 && sec2 == 0 && sec3 == 0) {
QMessageBox msgbox;
msgbox.setText("Cannot record a zero");
msgbox.exec();
}
else
ui->listWidget->addItem(
ui->label_3->text() + ":" + ui->label_2->text()
+ ":" + ui->label->text());
}
void Dialog::on_clear_clicked()
{
ui->listWidget->clear();
}
void Dialog::tick()
{
sec++;
sec2++;
sec3++;
float x = sec * 0.01;
int y = sec2 / 6000;
int z = sec3 / 360000;
ui->label->setNum(x);
if(x == 60) {
sec = 0;
}
ui->label_2->setNum(y);
if(y == 60) {
sec2 = 0;
}
ui->label_3->setNum(z);
}
void Dialog::paintEvent(QPaintEvent *event)
{
QColor minuteColor(0, 127, 127, 191);
int side = qMin(width(), height());
painter = new QPainter(this);
painter->setRenderHint(QPainter::Antialiasing);
painter->translate(width() / 2, height() / 2);
painter->scale(side /350.0, side / 350.0);
painter->setPen(QPen(minuteColor));
painter->drawArc(QRect(-95, -95, 190, 190),90 * 16, 360 * 16);
painter->setPen(minuteColor);
for (int j = 0; j < 60; j++) {
painter->drawLine(92, 0, 96, 0);
painter->rotate(6.0);
}
painter->setPen(QPen(QColor(127, 0, 127,191),5));
painter->rotate(6.0 * sec * 0.01);
painter->drawLine(0, -92, 0, -96);
}
I am relatively new to both Arduino and Processing and I have been working on a code that utilizes serial communication between the two. My Arduino code is reading and printing values from a piezo sensor and then sending the values to Processing, which sketches certain shapes based on the values. The code has worked previously, but for some reason it is no longer working. Everything compiles, but when I run the Processing code the sketch window is empty and remains empty. A few times the "error, disabling serialEvent()" showed up, but I just unplugged my Arduino board, closed out the programs, and restarted everything. The error no longer shows up, but my Processing sketch is still not displaying on the screen. Can someone please let me know what is wrong with my code? I really appreciate the help.
Arduino Code:
int ledPin = 13;
int knockSensor = A0;
byte val = 0;
int statePin = LOW;
int THRESHOLD = 5;
int sensorReading = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorReading = analogRead(knockSensor);
if(sensorReading > 0)
{
Serial.println(sensorReading, DEC);
}
if (sensorReading != 0)
Serial.println(sensorReading);
delay(100);
}
Processing Code:
import processing.serial.*;
Serial port;
int centerX = 550;
int centerY = 400;
float val;
float ellipseX;
float ellipseY;
float ellipseW;
float ellipseH;
float ellipseXX;
float ellipseYY;
float ellipseWW;
float ellipseHH;
float lineX;
float lineY;
float lineXX;
float lineYY;
void setup(){
background(255);
size(1100,800);
frameRate(10);
smooth();
String portname = "/dev/tty.usbmodem1411";
//String portname = Serial.list()[0];
port = new Serial(this, portname, 9600);
println(Serial.list());
//port.bufferUntil('\n');
}
void drawEllipse(float val)
{
if(val > 0 && val < 50)
{
ellipseX = random(540,560);
ellipseY = random(390,410);
ellipseW = val + 10;
ellipseH = val + 10;
stroke(0);
fill(random(255), random(200,255));
}
}
void drawLines(float val)
{
if(val > 50 && val < 70)
{
lineX = random(500, 600);
lineY = random(360, 440);
lineXX = random(500, 600);
lineYY = random(360, 440);
stroke(0);
}
}
void drawEllipse2(float val)
{
if(val > 70 && val < 120)
{
ellipseXX = random(460, 640);
ellipseYY = random(330, 470);
ellipseWW = val + random(20);
ellipseHH = val + 10;
stroke(0);
fill(random(50, 100), random(50, 100), random(50, 100), random(220, 255));
}
}
void serialEvent(Serial port)
{
String inString = port.readStringUntil('\n');
if (inString != null)
{
val = Float.parseFloat(inString);
}
drawEllipse(val);
drawLines(val);
drawEllipse2(val);
println(val);
}
Maybe using Serial.write() will be better. So the code will look like this.
Arduino Code:
int ledPin = 13;
int knockSensor = A0;
byte val = 0;
int statePin = LOW;
int THRESHOLD = 5;
int sensorReading = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorReading = analogRead(knockSensor);
if(sensorReading > 0)
{
Serial.println(sensorReading, DEC);
}
if (sensorReading != 0)
Serial.write(map(sensorReading, 0, 1023, 0, 255));
delay(100);
}
Processing Code:
import processing.serial.*;
Serial port;
int centerX = 550;
int centerY = 400;
float val;
float ellipseX;
float ellipseY;
float ellipseW;
float ellipseH;
float ellipseXX;
float ellipseYY;
float ellipseWW;
float ellipseHH;
float lineX;
float lineY;
float lineXX;
float lineYY;
void setup(){
background(255);
size(1100,800);
frameRate(10);
smooth();
String portname = "/dev/tty.usbmodem1411";
//String portname = Serial.list()[0];
port = new Serial(this, portname, 9600);
println(Serial.list());
//port.bufferUntil('\n');
}
void drawEllipse(float val)
{
if(val > 0 && val < 50)
{
ellipseX = random(540,560);
ellipseY = random(390,410);
ellipseW = val + 10;
ellipseH = val + 10;
stroke(0);
fill(random(255), random(200,255));
}
}
void drawLines(float val)
{
if(val > 50 && val < 70)
{
lineX = random(500, 600);
lineY = random(360, 440);
lineXX = random(500, 600);
lineYY = random(360, 440);
stroke(0);
}
}
void drawEllipse2(float val)
{
if(val > 70 && val < 120)
{
ellipseXX = random(460, 640);
ellipseYY = random(330, 470);
ellipseWW = val + random(20);
ellipseHH = val + 10;
stroke(0);
fill(random(50, 100), random(50, 100), random(50, 100), random(220, 255));
}
}
void serialEvent(Serial port)
{
if (0 < port.available()) {
val = map(port.read(), 0, 255, 0, 1023);
}
if (val > 0) {
drawEllipse(val);
drawLines(val);
drawEllipse2(val);
println(val);
}
}
I am writing a small program in Processing to display the values of a speed trap and elapsed time(like a drag strip, but for a waterslide for Australia Day) coming from a microcontroller over serial.
I have had the Processing sketch running and have done most of the development with just a mouse click to imitate new data and run the program, I also have set up the hardware and had it running with the microcontroller sending the serial data and the program displaying it.
I have done some further development, and now when it runs I am getting some strange things happening, boxes sometimes come through in the wrong color, some artifacts in the displayed numbers, and a lot of wrong colors for only some of the graph(the graph is made with a for loop and the color is set outside of it).
I have tried adding in some delays to make sure its getting a full string of data and I have also tried moving around the sub routines but nothing works.
The faults only appeared after I added in the elapsed time code to the serial data, before it was just one string, now it is two numbers separated by a colon.
I have put my code in here as well, its pretty straight forward, I am only new to programming, please excuse(and point out!) any errors.
import processing.serial.*;
Serial myPort;
float inString;
float inFloat0, inFloat1;
float[] list = new float[0];
float[] etlist = new float[0];
PFont f1, f2, f3, f4, f5, f6;
int index;
float rank;
float percentage;
int trapDistance = 1000;
int SgraphH = 38; //Speed graph scale
int ETgraphH = 15; //ET graph scale
int valueX = 0;
int valueY = 0;
boolean graph30 = false, graph690 = false;
color c1, c2, c3 = color(220, 0, 0), c4 = color(220, 0, 0);
int boxX = 295, boxY = 430, boxSize = 15; //Graph 30 box
void setup () {
size(1280, 700);
index = 0;
//Load list from textfile
String loadlist[] = loadStrings("list.txt");
for (int i = 0; i < loadlist.length; i++) {
String[] split = split(loadlist[i], ',');
list = append(list, float(split[0]));
etlist = append(etlist, float(split[1]));
index++;
}
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
//Create fonts
f1 = createFont("Arial Unicode MS", 20);
f2 = createFont("Arial Unicode MS", 240);
f3 = createFont("Arial Unicode MS", 35);
f4 = createFont("Arial Unicode MS", 15);
f5 = createFont("Arial Unicode MS", 15);
f6 = createFont("Arial Unicode MS", 12);
}
void draw () {
stroke(225);
fill(225);
rectMode(CORNER);
rect(0, 0, 500, 20);
fill(0);
text(mouseX, 20, 20);
text(mouseY, 50, 20);
text(mouseX - valueX, 80, 20);
text(mouseY - valueY, 110, 20);
}
void mousePressed() {
//Check if Mouse is over button and toggle Graph on
if (mouseX > boxX && mouseX < boxX+boxSize && mouseY >boxY && mouseY < boxY+boxSize) {
if (graph30) {
graph30 = false;
c3 = color(220, 0, 0);
}
else {
graph30 = true;
c3 = color(0, 220, 0);
}
create();
graphCheck();
graph();
}
//Check if Mouse is over button and toggle Graph on
if (mouseX > boxX+100 && mouseX < boxX+100+boxSize && mouseY >boxY && mouseY < boxY+boxSize) {
if (graph690) {
graph690 = false;
c4 = color(220, 0, 0);
}
else {
graph690 = true;
c4 = color(0, 220, 0);
}
create();
graphCheck();
graph();
}
}
void serialEvent (Serial myPort) {
delay(100);
String inString = myPort.readStringUntil('\n');
delay(100);
if (inString != null) {
inString = trim(inString);
String[] split = split(inString, ',');
inFloat0 = float(split[0]);
inFloat1 = float(split[1]);
index++;
float speed = trapDistance / inFloat0 * 3.6;
list = append(list, speed);
float et = inFloat1;
etlist = append(etlist, et);
//Clear screen
background(225);
//Run sub routines
create();
graphCheck();
graph();
}
}
void delay(int delay)
{
int time = millis();
while(millis() - time <= delay);
}
void create() {
//Clear screen
background(225);
//Sorting
float[] sortlist = new float[index+1];
sortlist = sort(list);
float[] sortetlist = new float[index+1];
sortetlist = sort(etlist);
//Calculate rank
int pos = 1;
while (list[index-1] > sortlist[pos - 1]) {
pos++;
}
if (pos == 1) {
rank = 0;
}
else {
rank = (pos / float(sortlist.length));
}
//Calculate Percentage of Speed
percentage = list[index-1] / sortlist[sortlist.length -1];
//Speed colour for fastest and slowest
if (index != 0) {
if (list[index-1] < sortlist[1]) {
c1 = color(240, 0, 0);
}
else if (list[index-1] > sortlist[index-1]) {
c1 = color(0, 240, 0);
}
else {
c1 = color(255);
}
}
else {
c1 = color(255);
}
//ET colour for fastest and slowest
if (index != 0) {
if (etlist[index-1] < sortetlist[1]) {
c2 = color(240, 0, 0);
}
else if (etlist[index-1] > sortetlist[index-1]) {
c2 = color(0, 240, 0);
}
else {
c2 = color(255);
}
}
else {
c2 = color(255);
}
//Boxes
rectMode(CORNER);
stroke(0);
fill(c1);
rect(15, 15, width-30, 200); //Speed
fill(c2);
rect(15, 230, width-30, 200); //ET
fill(255);
rect(15, height - 255, 125, 240); //Left
rect(155, height -255, 125, 240); //Left
rect(width - 140, height - 255, 125, 240); //Right
rect(width - 280, height - 255, 125, 240); //Right
//Text
fill(0);
textFont(f3);
textAlign(CENTER);
text("Speed", 78, height - 220);
text("ET", width - 78, height - 220);
text("ET", 218, height - 220);
text("Speed", width - 218, height - 220);
textFont(f4);
textAlign(LEFT);
text("Trap Distance: " + trapDistance + "mm", 2, height - 2);
//Big Numbers
textAlign(CENTER);
textFont(f2);
text(String.format("%.2f", list[index-1])+"km/h", width/2, 200); //Speed
text(String.format("%.2f", etlist[index-1])+"sec", width/2, 415); //ET
//Last 10
for (int i = 0; i <= index-1 && i < 10; i++) {
textAlign(LEFT);
textFont(f5);
text((index-1 - i + 1)+". "+String.format("%.3f", list[index-1 - i])+"km/h", 23, (height - 200 + (i * 20)));
}
//Last 10 ET
for (int i = 0; i <= index-1 && i < 10; i++) {
textAlign(LEFT);
textFont(f5);
text((index-1 - i + 1)+". "+String.format("%.3f", etlist[index-1 - i])+"sec", 163, (height - 200 + (i * 20)));
}
//Fastest
for (int i = 0; i <= index-1 && i < 10; i++) {
textAlign(CENTER);
textFont(f5);
text((i+1)+". "+String.format("%.3f", sortlist[sortlist.length - (i+1)])+"km/h", width - 220, (height - 200 + (i * 20)));
}
//Fastest ET
for (int i = 0; i <= index-1 && i < 10; i++) {
textAlign(CENTER);
textFont(f5);
text((i+1)+". "+String.format("%.3f", sortetlist[i])+"sec", width - 80, (height - 200 + (i * 20)));
}
//Create string for saving to text file
String[] listString = new String[index-1+1];
for (int i = 0; i < index-1+1; i++) {
listString[i] = (Float.toString(list[i]) + ',' + Float.toString(etlist[i]));
}
//Save to text file
saveStrings("list.txt", listString);
//Graph with curves
// beginShape();
// stroke(125, 125, 255);
// for (int i = 1; i <= index && i < 34; i++) {
// float y = map(list[index - (i - 1)], 0, SgraphH, 150, 0);
// curveVertex((width + 25 - (i * 25)), 25 + y);
// }
// endShape();
}
void graph() {
//Create graph area
fill(255);
rectMode(CENTER);
rect(width/2, height - 135, 690, 240);
stroke(192);
for (int i = 1; i < 30.; i++) {
line((((width - 690)/2) + (i * (690/30))), 446, ((((width - 690)/2) + (i * (690/30)))), 684);
}
for (int i = 1; i < 10; i++) {
line(((width - 690)/2)+1, (445 + (i * 24)), (width - (width - 690)/2)-1, (445 + (i * 24)));
}
//Graph last 690
if (graph690) {
stroke(0, 170, 0);
for (int i = 1; i <= index-1 && i < 690; i++) {
float start = map(list[index-1 - (i - 1)], 0, SgraphH, 240, 0);
float end = map(list[index-1 - i], 0, SgraphH, 240, 0);
line(((width - (width - 690)/2) + 1 - (i)), 445 + start, ((width- (width - 690)/2) + 1 - ((i + 1))), 445 + end);
}
}
//Graph last 690
if (graph690) {
stroke(120, 0, 120);
for (int i = 1; i <= index-1 && i < 690; i++) {
float start = map(etlist[index-1 - (i - 1)], 0, ETgraphH, 240, 0);
float end = map(etlist[index-1 - i], 0, ETgraphH, 240, 0);
line(((width - (width - 690)/2) + 1 - (i)), 445 + start, ((width- (width - 690)/2) + 1 - ((i + 1))), 445 + end);
}
}
//Graph last 30 speeds
if (graph30) {
stroke(0, 0, 240);
for (int i = 1; i <= index-1 && i < 31; i++) {
float start = map(list[index-1 - (i - 1)], 0, SgraphH, 240, 0);
float end = map(list[index-1 - i], 0, SgraphH, 240, 0);
line(((width - (width - 690)/2) + 23 - (i * 23)), 445 + start, ((width- (width - 690)/2) + 23 - ((i + 1) * 23)), 445 + end);
}
}
//Graph last 30 ETs
if (graph30) {
stroke(240, 0, 0);
for (int i = 1; i <= index-1 && i < 31; i++) {
float start = map(etlist[index-1 - (i - 1)], 0, ETgraphH, 240, 0);
float end = map(etlist[index-1 - i], 0, ETgraphH, 240, 0);
line(((width - (width - 690)/2) + 23 - (i * 23)), 445 + start, ((width- (width - 690)/2) + 23 - ((i + 1) * 23)), 445 + end);
}
}
fill(0);
textAlign(LEFT);
text("0", width / 2 - 345, height - 15);
text(SgraphH, width / 2 - 345, height - 243);
}
void graphCheck() {
//Draw box and text for graph selection
rectMode(CORNER);
textFont(f6);
textAlign(LEFT);
stroke(0);
fill(0);
text("Graph last 30", boxX+20, boxY+13);
fill(c3);
rect(boxX, boxY, boxSize, boxSize);
stroke(0);
fill(0);
text("Graph last 690", boxX+120, boxY+13);
fill(c4);
rect(boxX+100, boxY, boxSize, boxSize);
}
void keyPressed() {
valueX = mouseX;
valueY = mouseY;
}
Also, when triggered from a mouse click (turning on the graph's) it works fine.
Cheers,
Matt
I fixed it.
When the subroutines were being called by the serial trigger, it some how still allowed the looped code in the draw() function to still run, which was causing the issues.
I just put noLoop() and loop() in before and after the calls for the subroutines.
All good now.
I'm having a dilemma with this code and have no clue what to do. I'm pretty new to processing. This is a project from this link...
http://blog.makezine.com/2012/08/10/build-a-touchless-3d-tracking-interface-with-everyday-materials/
any help is massively appreciated... Thanks in advance
import processing.serial.*;
import processing.opengl.*;
Serial serial;
int serialPort = 1;
int sen = 3; // sensors
int div = 3; // board sub divisions
Normalize n[] = new Normalize[sen];
MomentumAverage cama[] = new MomentumAverage[sen];
MomentumAverage axyz[] = new MomentumAverage[sen];
float[] nxyz = new float[sen];
int[] ixyz = new int[sen];
float w = 256; // board size
boolean[] flip = {
false, true, false};
int player = 0;
boolean moves[][][][];
PFont font;
void setup() {
size(800, 600, P3D);
frameRate(25);
font = loadFont("TrebuchetMS-Italic-20.vlw");
textFont(font);
textMode(SCREEN);
println(Serial.list());
serial = new Serial(this, Serial.list()[serialPort], 115200);
for(int i = 0; i < sen; i++) {
n[i] = new Normalize();
cama[i] = new MomentumAverage(.01);
axyz[i] = new MomentumAverage(.15);
}
reset();
}
void draw() {
updateSerial();
drawBoard();
}
void updateSerial() {
String cur = serial.readStringUntil('\n');
if(cur != null) {
String[] parts = split(cur, " ");
if(parts.length == sensors) {
float[] xyz = new float[sen];
for(int i = 0; i < sen; i++)
xyz[i] = float(parts[i]);
if(mousePressed && mouseButton == LEFT)
for(int i = 0; i < sen; i++)
n[i].note(xyz[i]);
nxyz = new float[sen];
for(int i = 0; i < sen; i++) {
float raw = n[i].choose(xyz[i]);
nxyz[i] = flip[i] ? 1 - raw : raw;
cama[i].note(nxyz[i]);
axyz[i].note(nxyz[i]);
ixyz[i] = getPosition(axyz[i].avg);
}
}
}
}
float cutoff = .2;
int getPosition(float x) {
if(div == 3) {
if(x < cutoff)
return 0;
if(x < 1 - cutoff)
return 1;
else
return 2;
}
else {
return x == 1 ? div - 1 : (int) x * div;
}
}
void drawBoard() {
background(255);
float h = w / 2;
camera(
h + (cama[0].avg - cama[2].avg) * h,
h + (cama[1].avg - 1) * height / 2,
w * 2,
h, h, h,
0, 1, 0);
pushMatrix();
noStroke();
fill(0, 40);
translate(w/2, w/2, w/2);
rotateY(-HALF_PI/2);
box(w);
popMatrix();
float sw = w / div;
translate(h, sw / 2, 0);
rotateY(-HALF_PI/2);
pushMatrix();
float sd = sw * (div - 1);
translate(
axyz[0].avg * sd,
axyz[1].avg * sd,
axyz[2].avg * sd);
fill(255, 160, 0);
noStroke();
sphere(18);
popMatrix();
for(int z = 0; z < div; z++) {
for(int y = 0; y < div; y++) {
for(int x = 0; x < div; x++) {
pushMatrix();
translate(x * sw, y * sw, z * sw);
noStroke();
if(moves[0][x][y][z])
fill(255, 0, 0, 200);
else if(moves[1][x][y][z])
fill(0, 0, 255, 200);
else if(
x == ixyz[0] &&
y == ixyz[1] &&
z == ixyz[2])
if(player == 0)
fill(255, 0, 0, 200);
else
fill(0, 0, 255, 200);
else
fill(0, 100);
box(sw / 3);
popMatrix();
}
}
}
fill(0);
if(mousePressed && mouseButton == LEFT)
msg("defining boundaries");
}
void keyPressed() {
if(key == TAB) {
moves[player][ixyz[0]][ixyz[1]][ixyz[2]] = true;
player = player == 0 ? 1 : 0;
}
}
void mousePressed() {
if(mouseButton == RIGHT)
reset();
}
void reset() {
moves = new boolean[2][div][div][div];
for(int i = 0; i < sen; i++) {
n[i].reset();
cama[i].reset();
axyz[i].reset();
}
}
void msg(String msg) {
text(msg, 10, height - 10);
}
You are missing a class, in fact, more than one. Go back to the github and download, or copy and paste, all three codes, placing each one in a new tab named same name of the class (well this is not required, but is a good practice). The TicTacToe3D.pde is the main code. To make a new tab choose "new tab" from the arrow menu in Processing IDE (just below the standard button at the right). The code should run. WIll need an Arduino though to really get it working.