Processing on Arduino MEGA 2560
in
Integration and Hardware
•
1 years ago
I've been experimenting with processing on both the Arduino UNO and the MEGA 2560. This sketch works on the UNO (except for the additional pins) and trying to get it to work on the MEGA 2560. I've not been able to access the digital pins 22 - 53 on the MEGA. Wondering how to properly address these pins from processing.... using Standard Firmata 2.2.
This sketch is a bit of a hack of some of the sample programs in the examples.... grounding an input pin turns on the display in processing.... setting the pin HIGH and then grounding.... avoids floating inputs as when pin is set LOW.
I suppose I should add that it also works on the MEGA analog and PWM pins... can't seem to address the digital pins.
This sketch is a bit of a hack of some of the sample programs in the examples.... grounding an input pin turns on the display in processing.... setting the pin HIGH and then grounding.... avoids floating inputs as when pin is set LOW.
I suppose I should add that it also works on the MEGA analog and PWM pins... can't seem to address the digital pins.
- import processing.serial.*;
- import cc.arduino.*;
- Arduino arduino;
- color zone = color(150, 50, 150);
- color zoff = color(50, 50, 50);
- color back = color(50, 150, 50);
- color off = color(130, 179, 111);
- color on = color(50, 45, 100);
- color bar = color(255, 255, 255);
- int z;
- void setup() {
- size(670, 880);
- arduino = new Arduino(this, Arduino.list()[2], 57600); // adjust to your com port
- PFont font;
- font = loadFont("ComicSansMS-18.vlw"); // set to a font that you have
- textFont(font);
- }
- void draw() {
- background(back);
- stroke(on);
- for (int i = 2; i <= 12; i++){ // set these pins 2 - 12 as inputs and set high
- arduino.pinMode(i, Arduino.INPUT);
- arduino.digitalWrite(i, 1);
- }
- for (int i = 2; i <= 12; i++) {
- print (i);
- print (" ");
- println (arduino.digitalRead(i)); // added for debugging to see if it was writing to the inputs
- if (arduino.digitalRead(i) == 1){ // changes fill color based on pin status
- fill(zoff);
- }
- else {
- fill(zone);
- }
- rect(40 + i * 45, 40, 30, 30); // input boxes at the top
- rect(120 , 415 + i * 30, 20, 20); // input boxes at the bottom with text
- fill(bar);
- text("Input", 20, 430 + i * 30);
- text(i, 80, 430 + i * 30);
- }
- for (int i = 0; i <= 4; i++) { // graduations on the analog bar display
- stroke(bar);
- line(165 + i * 50, 140, 165 + i * 50, 380);
- stroke(200, 200, 200);
- line(140 + i * 50, 150, 140 + i * 50, 370);
- color(bar);
- fill(bar);
- text(20 + i * 20, 150 + i * 50, 410);
- }
- for (int i = 2; i <= 12; i++) { // input numbers on input boxes at the top
- fill(200, 200, 200);
- text(i, 50 + i * 44, 90);
- }
- for (int i = 0; i <= 5; i++) { // analog bars with analog reading on top
- fill(on);
- rect(110, 150 + i * 40, arduino.analogRead(i) / 4, 20);
- text("Analog", 20, 165 + i * 40);
- text(i, 80, 165 + i * 40);
- fill(200, 150, 150);
- text(arduino.analogRead(i)/10.24, 120, 167 + i * 40);
- }
- for (int z = 30; z <= 42; z++){ // for debugging to see if pins 30 - 42 are being written to
- arduino.pinMode(z, Arduino.INPUT);
- arduino.digitalWrite(z, 1);
- print (z);
- print (" ");
- println (arduino.digitalRead(z));
- }
- }
1