Formatting code in arduino ide saving in word

[table][tr][td][size=14pt][sub]Code:[/sub][/size][hr][/td][/tr][tr][td][size=9pt][tt]#include <EEPROM.h>
#include <avr/pgmspace.h>
void testEEPROM() {
uint8_t data[100];
for (int i = 0; i < 100; i++) data[i] = i;

unsigned long startWrite = micros();
for (int i = 0; i < 100; i++) EEPROM.write(i, data[i]);
unsigned long endWrite = micros();

unsigned long startRead = micros();
for (int i = 0; i < 100; i++) volatile byte x = EEPROM.read(i);
unsigned long endRead = micros();

Serial.print("EEPROM Write Time: "); Serial.println(endWrite - startWrite);
Serial.print("EEPROM Read Time: "); Serial.println(endRead - startRead);
}
void testSRAM() {
uint8_t ramArray[100];

unsigned long startWrite = micros();
for (int i = 0; i < 100; i++) ramArray[i] = i;
unsigned long endWrite = micros();

unsigned long startRead = micros();
for (int i = 0; i < 100; i++) volatile byte x = ramArray[i];
unsigned long endRead = micros();

Serial.print("SRAM Write Time: "); Serial.println(endWrite - startWrite);
Serial.print("SRAM Read Time: "); Serial.println(endRead - startRead);
}
void testSerial() {
uint8_t data[100];
for (int i = 0; i < 100; i++) data[i] = i;

unsigned long startWrite = micros();
for (int i = 0; i < 100; i++) Serial.write(data[i]);
unsigned long endWrite = micros();

Serial.println();
Serial.print("Serial Write Time (100 bytes): ");
Serial.println(endWrite - startWrite);
}
const uint8_t romData[100] PROGMEM = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99
};

void testROM() {
unsigned long startRead = micros();
for (int i = 0; i < 100; i++) {
volatile byte val = pgm_read_byte(&(romData[i]));
}
unsigned long endRead = micros();

Serial.print("ROM Read Time: "); Serial.println(endRead - startRead);
}
void [b]setup/b {
Serial.begin(9600);
delay(2000); // Wait for Serial to open

testEEPROM();
delay(1000);

testSRAM();
delay(1000);

testSerial();
delay(1000);

testROM();
}

void [b]loop/b {
// Nothing here
}[/tt][/size][/td][/tr][/table]

Hi @ankitakalra. I'm not sure I understand the meaning of your post.

Was there something you needed assistance with? If so, please provide a detailed description in a reply here on the forum topic.

Or were you instead only intending to share your sketch with the Arduino Forum community, and not looking for any assistance?

Read the pinned post re How to get the most from the Forum.

Yes, you can save formatted code in Word, but you need to understand formatting, and monospace. Word markups will be in your copy/paste. Here is your code, resuscitated.

#include <EEPROM.h>
#include <avr/pgmspace.h>

void testEEPROM() {
  uint8_t data[100];
  for (int i = 0; i < 100; i++)
    data[i] = i;

  unsigned long startWrite = micros();
  for (int i = 0; i < 100; i++)
    EEPROM.write(i, data[i]);

  unsigned long endWrite = micros();
  unsigned long startRead = micros();
  for (int i = 0; i < 100; i++)
    volatile byte x = EEPROM.read(i);
  unsigned long endRead = micros();

  Serial.print("EEPROM Write Time: ");
  Serial.println(endWrite - startWrite);
  Serial.print("EEPROM Read Time: ");
  Serial.println(endRead - startRead);
}

void testSRAM() {
  uint8_t ramArray[100];

  unsigned long startWrite = micros();
  for (int i = 0; i < 100; i++)
    ramArray[i] = i;
 
  unsigned long startRead = micros();
  for (int i = 0; i < 100; i++)
    volatile byte x = ramArray[i];
  unsigned long endRead = micros();

  unsigned long endWrite = micros();
  Serial.print("SRAM Write Time: ");
  Serial.println(endWrite - startWrite);
  Serial.print("SRAM Read Time: ");
  Serial.println(endRead - startRead);
}

void testSerial() {
  uint8_t data[100];
  for (int i = 0; i < 100; i++)
    data[i] = i;

  unsigned long startWrite = micros();
  for (int i = 0; i < 100; i++)
    Serial.write(data[i]);

  unsigned long endWrite = micros();
  Serial.println();
  Serial.print("Serial Write Time (100 bytes): ");
  Serial.println(endWrite - startWrite);
}

const uint8_t romData[100] PROGMEM = {
  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
  70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
  90, 91, 92, 93, 94, 95, 96, 97, 98, 99
};

void testROM() {
  unsigned long startRead = micros();
  for (int i = 0; i < 100; i++) {
    volatile byte val = pgm_read_byte(&(romData[i]));
  }
  unsigned long endRead = micros();

  Serial.print("ROM Read Time: ");
  Serial.println(endRead - startRead);
}

void setup() {
  Serial.begin(9600);
  delay(2000); // Wait for Serial to open

  testEEPROM();
  delay(1000);

  testSRAM();
  delay(1000);

  testSerial();
  delay(1000);

  testROM();
}

void loop() {
  // Nothing here
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.