Arduino multiple pin ADC read - arduino

Trying to read the value's from two analog sensors.
Can you use the for loop to read analog pins?
int i;
for (i = 0; i < 2; i = i + 1) {
x[I]=(analogRead(A[i]);
Working Code:
int AnalogpIn[2];
int MapValue[2];
void setup() {
Serial.begin(9600);
}
void loop() {
delay(100);
AnalogpIn[0] = analogRead(A0);
MapValue[0] = map(AnalogpIn[0], 0, 1023, 0, 255);
delay(100);
AnalogpIn[1] = analogRead(A1);
MapValue[1] = map(AnalogpIn[1], 0, 1023, 0, 255);
int i;
for (i = 0; i < 2; i = i + 1) {
Serial.print(AnalogpIn[i]);
Serial.print("-");
Serial.print(MapValue[i]);
Serial.println("");
delay (100);
}
}

Try this out,
I think this is what you are looking for. Have made few changes.
void loop(){
int i=0;
for (int i = 0; i < 2; i++) {
AnalogpIn[i] = analogRead(i);
MapValue[i] = map(AnalogpIn[i], 0, 1023, 0, 255);
Serial.print(AnalogpIn[i]);
Serial.print("-");
Serial.print(MapValue[i]);
Serial.println("");
}
delay (100);
}

Related

how to fix error "id return 1 exit status return code is not 0" in C++?

//Program by: Alim Mulyadi
//tgl: 21/02/2021
//Program: Countdown Timer Sederha1. na
[enter image description here](https://i.stack.imgur.com/58w5W.jpg)
#include <LiquidCrystal_I2C.h>
#include "Countimer.h"
Countimer tdown;
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#define pb_set A0 //Set
#define pb_up A1 //Up dan Start
#define pb_down A2 //Down, Pause, dan Reset
int relay = 4;
int buzzer = 9;
int set_detik = 0;
int set_menit = 0;
int set_jam = 0;
int last_set_detik = 0;
int last_set_menit = 0;
int last_set_jam = 0;
int set = 0;
bool kondisi_set = 0;
bool kondisi_relay = 0;
bool kondisi_reset = 0;
unsigned long lastmillis;
void setup() {
Serial.begin (9600);
pinMode(pb_set, INPUT_PULLUP);
pinMode(pb_up, INPUT_PULLUP);
pinMode(pb_down, INPUT_PULLUP);
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.begin();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Countdown Timer");
lcd.setCursor(0, 1);
lcd.print("By: Alim Mulyadi");
tdown.setInterval(print_time, 1000);
delay(2000);
lcd.clear();
}
void print_time() {
set_detik = set_detik - 1;
if (set_detik < 0) {
set_detik = 59;
set_menit = set_menit - 1;
}
if (set_menit < 0) {
set_menit = 59;
set_jam = set_jam - 1;
}
}
void loop() {
tdown.run();
if (digitalRead (pb_set) == 0) {
if (kondisi_set == 0 && kondisi_relay == 0) {
kondisi_set = 1;
set = set + 1;
if (set > 3) {
set = 0;
}
delay(100);
}
} else {
kondisi_set = 0;
}
if (digitalRead (pb_up) == 0) {
if (set == 0) {
tdown.start();
kondisi_relay = 1;
}
if (set == 1) {
set_detik++;
last_set_detik = set_detik;
}
if (set == 2) {
set_menit++;
last_set_menit = set_menit;
}
if (set == 3) {
set_jam++;
last_set_jam = set_jam;
}
if (set_detik > 59) {
set_detik = 0;
}
if (set_menit > 59) {
set_menit = 0;
}
if (set_jam > 99) {
set_jam = 0;
}
delay(200);
}
if (digitalRead (pb_down) == 0) {
//delay(500);
lastmillis = millis();
kondisi_reset = 0;
while (digitalRead (pb_down) == 0 && set == 0) {
if (millis() - lastmillis > 500) {
kondisi_reset = 1;
kondisi_relay = 0;
tdown.stop();
set_detik = last_set_detik;
set_menit = last_set_menit;
set_jam = last_set_jam;
lcd.setCursor(4, 1);
if (set_jam <= 9) {
lcd.print("0");
}
lcd.print(set_jam);
lcd.print(":");
if (set_menit <= 9) {
lcd.print("0");
}
lcd.print(set_menit);
lcd.print(":");
if (set_detik <= 9) {
lcd.print("0");
}
lcd.print(set_detik);
lcd.print(" ");
delay(100);
}
}
if (kondisi_reset == 0) {
if (set == 0) {
tdown.stop();
kondisi_relay = 0;
}
if (set == 1) {
set_detik--;
last_set_detik = set_detik;
}
if (set == 2) {
set_menit--;
last_set_menit = set_menit;
}
if (set == 3) {
set_jam--;
last_set_jam = set_jam;
}
if (set_detik < 0) {
set_detik = 59;
}
if (set_menit < 0) {
set_menit = 59;
}
if (set_jam < 0) {
set_jam = 99;
}
delay(200);
}
}
lcd.setCursor(0, 0);
if (set == 0) {
lcd.print(" Timer ");
}
if (set == 1) {
lcd.print(" Set Timer SS ");
}
if (set == 2) {
lcd.print(" Set Timer MM ");
}
if (set == 3) {
lcd.print(" Set Timer HH ");
}
lcd.setCursor(4, 1);
if (set_jam <= 9) {
lcd.print("0");
}
lcd.print(set_jam);
lcd.print(":");
if (set_menit <= 9) {
lcd.print("0");
}
lcd.print(set_menit);
lcd.print(":");
if (set_detik <= 9) {
lcd.print("0");
}
lcd.print(set_detik);
lcd.print(" ");
if (set_detik == 0 && set_menit == 0 && set_jam == 0 && kondisi_relay == 1) {
kondisi_relay = 0;
tdown.stop();
digitalWrite(relay, LOW);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
}
if (kondisi_relay == 1) {
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
delay(1);
}
I hope to find the answer

Pro trinket EEPROM read and write

(I am using Arduino IDE)
The Thing I am trying to achieve is it saving the "progress" even when the microcontroller turns off. I have tried for a while tweaking the code but I have yet to get it to actually save/read values from EEPROM properly, so here's the part of my code(Ignore the rest for running the display+i have removed all of the irrelevant code):
#include <EEPROM.h>
int hunger = 10000;
int happiness = 10000;
int y = 0;
int z = 0;
int sensorPin = A0;
int sensorPin2 = A1;
void setup() {
Serial.begin(9600);
EEPROM.write(5, 10000);
EEPROM.write(5, 10000);
hunger = EEPROM.read(8)- '0';
happiness = EEPROM.read(5)- '0';
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
display.clearDisplay();
display.display();
Serial.begin(9600);
pinMode(sensorPin,INPUT);
}
void loop() {
int value = happiness;
int value2 = hunger;
EEPROM.write(5, happiness);
EEPROM.write(8, hunger);
hunger -= 1;
happiness -= 1;
if(analogRead(sensorPin)>1020){
testhappy();
happiness+=2500;
}
else{
testsad();
}
while(analogRead(sensorPin2)>1020){
testeat();
hunger+=5000;
}
}
void testhappy(void){
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap(30, 32, Happy32_glcd_bmp, 32, 32, 1);
display.display();
delay(1);
display.display();
delay(1);
for(y=0;y<2;y++){
for(z=0;z<5;z++){
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap((30+z), 32, Happy32_glcd_bmp, 32, 32, 1);
display.display();
}
for(z=5;z!=0;z-=1){
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap((30+z), 32, Happy32_glcd_bmp, 32, 32, 1);
display.display();
}
for(z=0;z> -5;z-=1){
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap((30+z), 32, Happy32_glcd_bmp, 32, 32, 1);
display.display();
}
for(z=0-5;z!=0;z+=1){
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap((30+z), 32, Happy32_glcd_bmp, 32, 32, 1);
display.display();
}
}
display.stopscroll();
}
void testsad(void){
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap(30, 32, Mild32_glcd_bmp, 32, 32, 1);
display.display();
delay(1);
}
void testeat(void){
delay(200);
for(y=0;y<6;y++){
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap(30, 32, Eat32_glcd_bmp, 32, 32, 1);
display.drawBitmap(60, 38, Cookie18_glcd_bmp, 8, 8, 1);
display.display();
delay(200);
display.clearDisplay();
display.setCursor(0,0);
display.print(hunger/100);display.print("/");display.print(happiness/100);
display.drawBitmap(60, 38, Cookie28_glcd_bmp, 8, 8, 1);
display.drawBitmap(30, 32, Mild32_glcd_bmp, 32, 32, 1);
display.display();
delay(200);
}
}
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];
// initialize
for (uint8_t f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;
Serial.print("x: ");
Serial.print(icons[f][XPOS], DEC);
Serial.print(" y: ");
Serial.print(icons[f][YPOS], DEC);
Serial.print(" dy: ");
Serial.print(icons[f][DELTAY], DEC);
}
while (1) {
// draw each icon
for (uint8_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
}
display.display();
delay(200);
// then erase it + move it
for (uint8_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
// move it
icons[f][YPOS] += icons[f][DELTAY];
// if its gone, reinit
if (icons[f][YPOS] > display.height()) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;
}
}
}
}
(I am getting no errors when compiling the code)
Look here at the page for EEPROM.write here. https://www.arduino.cc/en/Reference/EEPROMWrite
There it says the arguments are defined as:
EEPROM.write(address, value)
Parameters address: the location to write to, starting from 0 (int)
value: the value to write, from 0 to 255 (byte)
Now look at the number you're trying to write into EEPROM:
EEPROM.write(5, 10000);
Hopefully now you can see what the problem is. Your second argument is far too large. You should break it into two bytes or use a different method like EEPROM.put (look that up) which doesn't suffer this limitation.

Error with Arduino/Processing serial communication

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);
}
}

.bss will not fit into region ram

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;

Cannot find class type name "Normalized"- Processing

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.

Resources