Let's Make Robots!

Forum suggestion

ByJAX

You know what would be excellent? A code box for forum posts. You know what I mean? Keep that posted code contained in a box to preserve the aesthetics of the post itself. Yeah.

Two cents :ching:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rogue's picture

It would really help clean up pages where people are posting large code snippets back and forth.  I see the hand broom icon in the comment window will clean up messy code, not the same thing.

TinHead's picture

... why not use it as it makes code appear as below?

def main():
print("this is some code")
print("another line of code")

Oh yeah not so nice though ... it actually take a lot of html hacking to get it print nicely :/

Maybe there is some nice Drupal plugin that could be used?

JAX's picture

The thing is when someone puts in some lengthy code you have to navigate through it whether you want to or not. I guess what I was looking for was an HTML Text Box. Neat little box. Scroll bars. Yeah.

goofybob's picture

Hrm, looks like someone's Arduino threw up in here...

airuno2l's picture

I think it's a must have.

arbarnhart's picture

You mean something like this:

void setup()
{ pinMode(8, OUTPUT);
}
etc
etc
etc
etc
etc

Sorry, I just don't think that's possible.

Hmm - maybe it isn't after all. It has a scroll bar when editing.

Let me try something different (holy smokes - this is even worse):

/*
* Set up the accelerometer and gyroscope in the IMU.
 * Read data from them and spit it out on the serial port.
 *
 * JRW 12/11/10
 */
 
#include <Wire.h> /
 
#include "i2c.h"
#include "adxl345.h"
#include "itg3200.h"
#include "IMUfilter.h"
 
#define GYRO 0x68
#define ACCEL 0x53
#define FILTER_RATE 0.01
 
ADXL adxl(ACCEL);
ITG itg(GYRO);
IMUfilter imuFilter(FILTER_RATE, 0.6);
int count=0;
long lastmillis=0;
 
float ax=0,ay=0,az=0,gx=0,gy=0,gz=0;
float loops=0;
float sumx,sumy,sumz=0;
 
void setup() {
  i2c.begin();
  Serial.begin(57600);
  Serial.println("I2C initialised.");
  adxl.init();
  itg.init();
  itg.wake();
  
  while (!itg.dataReady()) {
  }
  
  unsigned char whoami=i2c.readRegister(ACCEL,ADXL_WHO_AM_I);
  Serial.print("Accel: ");
  Serial.println(whoami,HEX);
 
  whoami=i2c.readRegister(GYRO,ITG_WHO_AM_I);
  Serial.print("Gyro: ");
  Serial.println(whoami,HEX);
  Serial.print("Temp: ");
  Serial.println(itg.getTemp());
 
  /*Serial.println(i2c::readRegister(ACCEL, ADXL_TIME_INACT),DEC);
   Serial.println(i2c::readRegister(ACCEL, ADXL_THRESH_INACT),DEC);
   Serial.println(i2c::readRegister(ACCEL, ADXL_ACT_INACT_CTL),BIN);
   Serial.println(i2c::readRegister(ACCEL, ADXL_POWER_CTL),BIN);
   delay(5000);*/
  //Serial.println(i2c::readRegister(GYRO, ITG_PWR_MGM),BIN);
  //delay(2000);
}
 
void loop() {
 
    while (!adxl.dataReady()) {
    }
    if (adxl.sleeping()) {
      Serial.println("Sleeping");
    }
    else
    {
      ax+=adxl.getX();
      ay+=adxl.getY();
      az+=adxl.getZ();
      /*Serial.print(ax);
       Serial.print('\t');
       Serial.print(ay);
       Serial.print('\t');
       Serial.println(az);*/
    }
    while (!itg.dataReady()) {
    }
    gx+=(float)itg.getX();
    gy+=(float)itg.getY()*PI/180.0;
    gz+=(float)itg.getZ()*PI/180.0;
    loops++;
    //}
 
  long current=millis();
  if (current-lastmillis>FILTER_RATE*1000) {
    lastmillis=current;
    imuFilter.updateFilter(gx/loops*PI/180.0, gy/loops*PI/180.0, gz/loops*PI/180.0, ax, ay, az);
    imuFilter.computeEuler();
    sumx+=gx/loops*FILTER_RATE;
    sumy+=gy/loops*FILTER_RATE;
    sumz+=gz/loops*FILTER_RATE;
    /*Serial.print(ax);
     Serial.print('\t');
     Serial.print(ay);
     Serial.print('\t');
     Serial.println(az);*/
 
    if (count++>10) {
      Serial.print(imuFilter.getPitch()/PI*180.0);
      Serial.print('\t');
      Serial.print(imuFilter.getRoll()/PI*180.0);
      Serial.print('\t');
      Serial.print(imuFilter.getYaw()/PI*180.0);
      Serial.print('\t');
      Serial.print(sumx);
      Serial.print('\t');
      Serial.print(sumy);
      Serial.print('\t');
      Serial.println(sumz);
      count=0;
      /*Serial.print(itg.getX());
       Serial.print('\t');
       Serial.print(itg.getY());
       Serial.print('\t');
       Serial.print(itg.getZ());
       Serial.print('\t');
       Serial.print(adxl.getX());
       Serial.print('\t');
       Serial.print(adxl.getY());
       Serial.print('\t');
       Serial.println(adxl.getZ());*/
      /*Serial.print(imuFilter.q0);
       Serial.print('\t');
       Serial.print(imuFilter.q1);
       Serial.print('\t');
       Serial.print(imuFilter.q2);
       Serial.print('\t');
       Serial.println(imuFilter.q3);*/
    }
  ax=0,ay=0,az=0,gx=0,gy=0,gz=0;
  loops=0;
  }
  else {
    //Serial.println("Waiting");
  }
}
 
 
GranTotem's picture

You mean like in many forums where code is inside a box so it looks better?

Good idea!