[BUG] STuff like "CODE" on new forum.???

I tried putting some code in, which came from the arduino IDE "Copy For Forum". It looks like this:

[quote]
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]([color=#006699]"TEST 003 - Digital Pins Sink Current"[/color]);  
  [color=#CC6600]pinMode[/color](2, [color=#006699]OUTPUT[/color]);      [color=#7E7E7E]// Set Load pin to Output mode[/color]

  [color=#CC6600]for[/color] (  DigPort2Test = FirstDigPort; 
         DigPort2Test <= LastDigPort;
         DigPort2Test ++)
  {[color=#7E7E7E]// Loop thru Source Tests[/color]
    [color=#CC6600]digitalWrite[/color](2, [color=#006699]HIGH[/color]);              [color=#7E7E7E]// Connect HIGH Load[/color]

    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"Digital pin "[/color]);
    [color=#CC6600]delay[/color](1000);    
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](DigPort2Test, [color=#006699]DEC[/color]);     
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]" Sink Test "[/color]);    
    [color=#CC6600]pinMode[/color](DigPort2Test, [color=#006699]OUTPUT[/color]);      [color=#7E7E7E]// Set tested pin to Output mode[/color]

    [color=#CC6600]digitalWrite[/color](DigPort2Test, [color=#006699]LOW[/color]);  [color=#7E7E7E]// Pin Sources current HIGH     [/color]
    [color=#CC6600]delay[/color](1000);
    IntVoltsRead = [color=#CC6600]analogRead[/color](A0);
    FloatVoltsRead = a2d2float (IntVoltsRead);
    [color=#CC6600]pinMode[/color](DigPort2Test, [color=#006699]INPUT[/color]);      [color=#7E7E7E]// ReSet tested pin to Input mode   [/color]
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"VoltsRead = "[/color]);
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](FloatVoltsRead,2);  

[/quote]

Am I doing that right

AND.. the keyboard hung right in the middle of typing... Which also happened on an earlier attempt to post...

Hmmm... What is the right way to put code in now????

Regards, Terry King ..On the Red Sea at KAUST.edu.sa
terry@terryking.us

Testing testing... is this on?

#include <Servo.h> 
Servo myservo;
Servo myservo2;

#include <Wire.h>
#include "nunchuck_funcs.h"
byte accx,accy,zbut,cbut;


const int numReadings = 50;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int readings2[numReadings];      // the readings from the analog input
int index2 = 0;                  // the index of the current reading
int total2 = 0;                  // the running total
int average2 = 0;                // the average

int inputPin = 0;

void setup()
{
  myservo.attach(8);
  myservo2.attach(10);

  Serial.begin(19200);
  nunchuck_setpowerpins();
  nunchuck_init(); // send the initilization handshake

  for (int thisReading = 0; thisReading < numReadings; thisReading++)
  {
    readings[thisReading] = 0;
  }

  for (int thisReading2 = 0; thisReading2 < numReadings; thisReading2++)
  {
    readings2[thisReading2] = 0;
  }
}

void loop()
{
  nunchuck_get_data();
  accx  = nunchuck_accelx(); // ranges from approx 70 - 182
  accy  = nunchuck_accely(); // ranges from approx 65 - 173
  zbut = nunchuck_zbutton();
  cbut = nunchuck_cbutton(); 


  total = total - readings[index];
  readings[index] = map(accx, 70, 182, 0, 180);
  total = total + readings[index];
  index = index + 1;                    
  if (index >= numReadings)
  {
    index = 0;                           
  }

  int pos = total / numReadings;
  myservo.write(map(pos, 0, 180, 50, 180));


  total2 = total2 - readings2[index2];
  readings2[index2] = map(accy, 65, 173, 0, 180);
  total2 = total2 + readings2[index2];
  index2 = index2 + 1;                    
  if (index2 >= numReadings)
  {
    index2 = 0;                           
  }

  pos = total2 / numReadings;
  myservo2.write(map(pos, 0, 180, 45, 160));

  delay(15);
}

Seems to look right when I do it.

bld, try again.

In the Arduino editor go to Edit > Copy for forum. Don't just highlight the code and copy/paste.

Terry, I'm sure that feature was just for the previous forum. They will either have to tweak this forum so that the formatting tags work inside code tags or that "copy for forum" will be removed from the next software update.

For now I'd just do a regular old copy/paste.

ah, lol... Never noticed it was there xD

/*

  • Code for cross-fading 3 LEDs, red, green and blue, or one tri-color LED, using PWM
  • The program cross-fades slowly from red to green, green to blue, and blue to red
  • originally "dimmingLEDs" by Clay Shirky clay.shirky@nyu.edu
    */

// Output
int redPin = 3; // Red LED, connected to digital pin 9
int greenPin = 5; // Green LED, connected to digital pin 10
int bluePin = 9; // Blue LED, connected to digital pin 11

// Program variables
int redVal = 1; // Variables to store the values to send to the pins
int greenVal = 1; // Initial values are all off
int blueVal = 1;

int i = 0; // Loop counter
int wait = 5; // 50ms (.05 second) delay; shorten for faster fades

void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

// Main program
void loop()
{
i += 1; // Increment counter
{
redVal =((i<255)i)+((i>=255)255)+((i>511)(512-i))+((i>766)(i-766))+((i>=1276)(i-1276))+((i>1530)(1530-i))+((i>1786)(1786-i));
greenVal =(i<256)
(1)+(i>255)(i-255)+(i>510)(510-i)+(i>1020)(1020-i)+(i>1274)(i-1274)+(i>1530)(i-1531)+(i>1785)(3571-(2i));
blueVal =(i<764)
(1)+(i>765)(i-765)+(i>1020)(1020-i)+(i>1786)*(1786-i);
}

if (i > 2040) //
{
i = 1;
}

// we do "255-redVal" instead of just "redVal" because the
// LEDs are hooked up to +5V instead of Gnd
analogWrite(redPin, redVal); // Write current values to LED pins
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);

delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}

But what is the problem here then?

What you was doing, was to put it into a [ code] tag, and everything between those will get encoded into html safe, so they will be shown right, and not processed.

Well, if you put it in a quote like that it looks nice. But if you put it in [ code ] like on the old forum then it doesn't take the formatting.

Also you have a smilie in there.

biocow:
Well, if you put it in a quote like that it looks nice. But if you put it in [ code ] like on the old forum then it doesn't take the formatting.

Never noticed it used on the old forum. And the quote stuff is something it copies to clipboard by itself, I didn't put it there myself.

OK, let me Try That Again.. (I seem to say that a LOT lately) :slight_smile:

Just plain PASTE what is on the clipboard from COPY FOR FORUM:
(code fragment)

/---------( TEST 2 )----------------------/
Serial.println();
Serial.println("TEST 002 - Digital Pins Source Current");
pinMode(2, OUTPUT); // Set Load pin to Output mode
for ( DigPort2Test = FirstDigPort;
DigPort2Test <= LastDigPort;
DigPort2Test ++)
{//Loop thru Source Tests
digitalWrite(2, LOW); // Connect Low Load

Serial.print("Digital pin ");
// delay(A2D_Delay);
Serial.print(DigPort2Test, DEC);
Serial.print(" Source Test ");
pinMode(DigPort2Test, OUTPUT); // Set tested pin to Output mode

digitalWrite(DigPort2Test, HIGH); // Pin Sources current HIGH
delay(A2D_Delay);
IntVoltsRead = analogRead(A0);
FloatVoltsRead = a2d2float (IntVoltsRead);
pinMode(DigPort2Test, INPUT); // ReSet tested pin to Input mode
Serial.print("VoltsRead = ");
Serial.print(FloatVoltsRead,2);

if (FloatVoltsRead > LowVoltResultOK
&& FloatVoltsRead < HighVoltResultOK)
{
Serial.println(" -- OK!");
}
else
{
Failure ++;
Serial.println(" ** Source FAIL ** ");
}
}//END Loop thru Source Tests
Serial.println();

Let's look at that....

OK! Thanks!

Regards, Terry King ..On the Red Sea at KAUST.edu.sa
terry@terryking.us

My turn:

First using a quote window

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

Now same content in code window:

[quote]
[color=#7E7E7E]/*[/color]
[color=#7E7E7E]  Blink[/color]
[color=#7E7E7E]  Turns on an LED on for one second, then off for one second, repeatedly.[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E]  This example code is in the public domain.[/color]
[color=#7E7E7E] */[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {                
  [color=#7E7E7E]// initialize the digital pin as an output.[/color]
  [color=#7E7E7E]// Pin 13 has an LED connected on most Arduino boards:[/color]
  [color=#CC6600]pinMode[/color](13, [color=#006699]OUTPUT[/color]);     
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
  [color=#CC6600]digitalWrite[/color](13, [color=#006699]HIGH[/color]);   [color=#7E7E7E]// set the LED on[/color]
  [color=#CC6600]delay[/color](1000);              [color=#7E7E7E]// wait for a second[/color]
  [color=#CC6600]digitalWrite[/color](13, [color=#006699]LOW[/color]);    [color=#7E7E7E]// set the LED off[/color]
  [color=#CC6600]delay[/color](1000);              [color=#7E7E7E]// wait for a second[/color]
}

[/quote]

Lets look:

So I guess the rule is don't post code into a code window? :slight_smile:

Lefty

retrolefty:
Lets look:
So I guess the rule is don't post code into a code window? :slight_smile:
Lefty

And... Don't hit the HELP button, either :~

You may have noticed.. I had earlier commented that it seems rather silly that QUOTE formats/highlights the pasted code somewhat and all we really get from CODE is a mono spaced font. (Essentially a

 html tag)

The highlighter inside the "quote" feature is, to my old eyes, nearly unreadable.

Really hope this gets analyzed soon by the mods

The "code" tags explicitly DO NOT PROCESS the text between the tags. You would have gotten similar weird looking results on the old forum.
"copy for forum" makes code into pretty quotes, but a plain copy between code tags makes for something that people can cut and paste back into the IDE.

[quote author=Terry King link=topic=50156.msg357384#msg357384 date=1296166710]
I tried putting some code in, which came from the arduino IDE "Copy For Forum". It looks like this:[/quote]

retrolefty:
don't post code into a code window

Suppose you are going to start a new topic. (Click the "New Topic" button on one of the sub-forums.) Here is a recipe for posting code:

  • In the Arduino IDE, highlight the code that you are going to post.
  • Copy/Paste the code into the edit part of the "New Topic" window of the forum
  • Highlight the code in the edit pane. (Not your narrative or other text, just the code.)
  • Click the "#" on the second row of icons of the "New Topic" window
  • Click the "Preview" button at the bottom of the window.

It puts "code tags" around the highlighted part. That preserves formatting and shows the code in a nice, clear monospace font. (Who needs that annoyingly ugly and inconsistent color highlighting when posting code here, anyhow?)

Here's some code in "code tags." (See Footnote.)

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

Click the "Preview" button at the bottom of the window.

Of course if you are going to reply to a particular post rather than starting a new thread, you click the "Reply" button on that post and go through the same steps in the edit window.

Regards,

Dave

Footnote:
If you want to see how other people get their stuff to look the way that it does, then click the "Quote" button in the window of that response. (Pretend you are going to reply.)

It shows the various markup tags that were used. Most of them can be applied by highlighting some stuff and clicking one of the icons in the "Post reply" window. (Or you can enter them yourself.)

It would be a Good Thing if people would always (always) click "Preview" before posting, and it would be a Really Good Thing if people would not post the entire thread when using the "Quote" button. (But I'm not holding my breath...)

This is a pretty valuable topic. I will add the comments to my todo list. Obviously we should have a proper functionality for this. Code should come for Code and not for Quote ... we will fix it, but there are other things to fix first,

thanks, I keep it open so that I don't forget

/d