Se afișează postările cu eticheta prezentare frumoasa cod. Afișați toate postările
Se afișează postările cu eticheta prezentare frumoasa cod. Afișați toate postările

marți, 1 octombrie 2013

Prezentare "frumoasa" sketch/program in articol (II)

   In precedentul articol am prezentat cum afisez frumos un cod/program/sketch, apoi cum fac un text de dimensiuni mari sa fie afisat intr-o fereastra mica.
   Deoarece nu vreau sa instalez programe si alte "ajutoare", am mai cautat si am ajuns la concluzia ca am cautat prea departe, in sensul ca inclusiv programul Arduino IDE are facilitatea de a copia codul si a-l transforma in cod HTML, sketch-ul aratand intuitiuv (cu anumite culori, de exemplu):

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

   Acest tip de prezentare nu elimina problema textelor lungi, asa ca e vreu ceva de genul:
/*
original sketch made by niq_ro ( http://www.tehnic.go.ro )
Santuhalm, Romania, 30.7.2013
revised (1.3.3) sketch in 25.8.2013, Craiova

*/
int u1 = 0; // initial voltage value from sensor;
float u = 0.00; // initial calculated voltage value; 
int i1 = 0; // initial current value;
float i = 0.00; // initial calculated current value;
int t1 = 0; // initial temperature value;
float t = 0.00; // initial calculated temperature value; 

int voltagePin = A4; // divider from measuread voltge is put at analog input no.4
int currentPin = A3; // output from ACS712 is put at analog input no.3
int temperaturePin = A5; // output from LM335 is put at analog input no.5


// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);


void setup() {                
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(1, 0);
  lcd.print("indicator panou");
  lcd.setCursor(1, 1);
  lcd.print("ramura negativa");
  delay(2000);
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("versiune 1.3.3");
  lcd.setCursor(4, 1);
  lcd.print("by niq_ro");
  delay(2000);
 // lcd.clear();
 
}


void loop() {
  
float u2 = 0; 
float i2 = 0;
float t2 = 0;
  for (int x=1; x <= 5; x++)
  {
// calculate the value  
u1 = analogRead(voltagePin); // read value from voltage divider;
u = 105*u1/1023.0; // calculated value for input voltage;
u2 = u2 + u;

i1 = analogRead(currentPin); // read value from current sensor (ACS712);
i = 10.0*(5.0*i1/1023.0-2.5); // calculated value for input current using ACS712-20;
i2 = i2 + i;

t1 = analogRead(temperaturePin); // read value from temperature sensor (LM335);
t = 100.0*(5.0*t1/1023.0-2.980)+25.0;
t2 = t2 + t;

delay (200);
  }   

u = u2/5.0; // average and corrected voltage
i = i2/5.0 + 0.05; // average and corrected current
t = t2/5.0 - 8.0 ; // average and corrected temperature
 
// Print a message to the LCD.
  lcd.clear();
  
  // show the voltage value
  if (u >= 100.0) 
  {
    lcd.setCursor(0, 0);
    lcd.print("-");
    lcd.print(u,1);
    lcd.print("V");
  }
  else
  if (u >= 10.0) 
    {
    lcd.setCursor(1, 0);
    lcd.print("-");
    lcd.print(u,1);
    lcd.print("V");
    }
  else  
  if (u > 0.0) 
  { lcd.setCursor(2, 0);
    lcd.print("-");
    lcd.print(u,1);
    lcd.print("V");
  }  
    else
   { lcd.setCursor(3, 0);
    lcd.print(u,1);
    lcd.print("V");
   } 
  // show the current value
  if (i >= 10.0) 
    {
    lcd.setCursor(1, 1);
    lcd.print("+");
    lcd.print(i,1);
    lcd.print("A");
    }
  else  
  if (i > 0.0) 
  { lcd.setCursor(2, 1);
    lcd.print("+");
    lcd.print(i,1);
    lcd.print("A");
  }
  else
  if (i < -10.0) 
  { lcd.setCursor(1, 1);
    lcd.print(i,1);
    lcd.print("A");
  }
  else
  if (i < 0.0) 
  { lcd.setCursor(2, 1);
    lcd.print(i,1);
    lcd.print("A");
  }  
    else
  {  lcd.setCursor(3, 1);
    lcd.print(i,1);
    lcd.print("A");
  }
 
   // show the power value
float p=i*u;
  if (p < 0.0) p = -p;
  if (p >= 1000.0)
  {
  lcd.setCursor(11, 0);
  }
  else
  if (p >= 100.0)
  {
  lcd.setCursor(12, 0);
  }
  else
  if (p >= 10.0)
  {
  lcd.setCursor(13, 0);
  }
  else lcd.setCursor(14, 0);
  lcd.print(p,0);
  lcd.print("W");


   // show the temperature value
 if (t >= 100.0) 
    {
    lcd.setCursor(8, 1);
    lcd.print("+");
    lcd.print(t,1);
    lcd.write(0b11011111);
    lcd.print("C");
    }
  else  
  if (t >= 10.0) 
  { lcd.setCursor(9, 1);
    lcd.print("+");
    lcd.print(t,1);
    lcd.write(0b11011111);
    lcd.print("C");
  }
  else
  if (t >= 0.0) 
  { lcd.setCursor(10, 1);
    lcd.print("+");
    lcd.print(t,1);
    lcd.write(0b11011111);
    lcd.print("C");
  }
  else
  if (t < -10.0) 
  { lcd.setCursor(9, 1);
    lcd.print("+");
    lcd.print(t,1);
    lcd.write(0b11011111);
    lcd.print("C");
  }
  else
  { lcd.setCursor(10, 1);
    lcd.print(t,1);
    lcd.write(0b11011111);
    lcd.print("C");
  }  
delay(1000);
}

   Toata smecheria este in adaugarea urmatorului text, in sursa paginii (html):
 <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: 200px; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">  
inaintea textului selectat si copiat ca HTML din Arduino IDE,
iar la final trebuie pus:
 </code>/<pre>  
 </p>  

   Un alt exemplu de sketch:
/*.............................................................
Sending Multiple Variables Using VirtualWire. Receiver
Author: Rodrigo Mompo Redoli
For http://controlrobotics.rodrigomompo.com
adapted sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com
..............................................................*/
#include <VirtualWire.h>
#include <Time.h>  
// Sensors 
int Sensor1Data;
int Sensor2Data;
int Sensor3Data;
int Sensor4Data;
  
char StringReceived[22]; 
// other  
int led = 13; //pin for LED
int j=1; // count the messages
  
void setup() {
  // set the time for record time and value
   setTime(0,0,0,25,9,13); // set time to Saturday 8:29:00am Jan 1 2011

pinMode(led, OUTPUT); 

  // VirtualWire 
    // Initialise the IO and ISR
    // Required for DR3100

    // Bits per sec
    vw_setup(2000);
    vw_set_rx_pin(11);  
      
    // Start the receiver PLL running
    vw_rx_start();       

Serial.begin(9600);
Serial.println("Receptorul lui niq_ro e pregatit sa primeasca mesaje..."); 

  
} // END void setup
  
void loop(){
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
      
//Taking the data from the control base
    if (vw_get_message(buf, &buflen)) 
    {
      digitalWrite(led, HIGH);
Serial.print("Pachet date nr. "); // print a message
Serial.print(j); // number of message
Serial.print(": ");
 int i;
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
 {            
          // Fill Sensor1CharMsg Char array with corresponding 
          // chars from buffer.   
          StringReceived[i] = char(buf[i]);
     //     Serial.print(StringReceived[i]);
 }
  
      sscanf(StringReceived, "%d,%d,%d,%d,%d,%d",&Sensor1Data, &Sensor2Data,&Sensor3Data,&Sensor4Data); // Converts a string to an array
//Serial.print();
  if (hour()<10) Serial.print("0");
  Serial.print(hour());
  Serial.print(":");
  if (minute()<10) Serial.print("0");
  Serial.print(minute());
  Serial.print(":");
  if (second()<10) Serial.print("0");
  Serial.print(second());
Serial.print(" - ");
digitalWrite(led, LOW);        
Serial.print(Sensor1Data);
Serial.print(", ");
Serial.print(Sensor2Data);
Serial.print(", ");
Serial.print(Sensor3Data);
Serial.print(" & ");
Serial.println(Sensor4Data);
        // Turn off light to and await next message 
j=j++; // count the message         
    }
  
 memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived
}


sâmbătă, 20 iulie 2013

Prezentare "frumoasa" sketch/program in articol

   Am gasit pe un site, prezentare frumoasa a unui sketch pentru Arduino, e vorba de program.., eu il selectam, schimbam tipul de text si culoare si.. cam atat, ceva de genul:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adresss for LCC 16x2
void setup(){
   lcd.init(); 
  lcd.backlight(); //backlight is now ON
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a logo message to the LCD.
  lcd.print("www.tehnic.go.ro");  
  lcd.setCursor(0, 1);
  lcd.print("creat de niq_ro");
  delay (2500);
  lcd.clear();
   
  // Print a permanent message to the LCD.
  lcd.print(" teste interfata");
  lcd.setCursor(0, 1);
  lcd.print("i2c pt. LCD 16x2");
  delay (2500);
}
void loop(){
    delay(1000);
}

dar am gasit la Source Code Formatter for Blogger, Blogspot , Blog & Blogging, Format Formatting Tool un utilitar de formatare, astfel ca acel cod va arata asa:


 #include <Wire.h>  
 #include <LiquidCrystal_I2C.h>  
 LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adresss for LCC 16x2  
 void setup(){  
   lcd.init();   
  lcd.backlight(); //backlight is now ON  
  // set up the LCD's number of columns and rows:   
  lcd.begin(16, 2);  
  // Print a logo message to the LCD.  
  lcd.print("www.tehnic.go.ro");   
  lcd.setCursor(0, 1);  
  lcd.print("creat de niq_ro");  
  delay (2500);  
  lcd.clear();  
  // Print a permanent message to the LCD.  
  lcd.print(" teste interfata");  
  lcd.setCursor(0, 1);  
  lcd.print("i2c pt. LCD 16x2");  
  delay (2500);  
 }  
 void loop(){  
   delay(1000);  
 }  

   O "captura" de ecram a acelui site este:


duminica, 21.iul.2013
   Poate nu am fost explicit, deoarece acel sketch nu era foarte lung, dar unul de peste 400 de linii, de genul ultimului din articolul Afisaje LED cu 7 segmente si.. Arduino (II), care arata asa:
/*
 6-13-2011
 Spark Fun Electronics 2011
 Nathan Seidle

 This code is public domain but you buy me a beer if you use this and we meet 
 someday (Beerware license).

 4 digit 7 segment display:
 Datasheet: 

 This is an example of how to drive a 7 segment LED display from an ATmega
 without the use of current limiting resistors. This technique is very common 
 but requires some knowledge of electronics - you do run the risk of dumping 
 too much current through the segments and burning out parts of the display. 
 If you use the stock code you should be ok, but be careful editing the 
 brightness values.

 This code should work with all colors (red, blue, yellow, green) but the 
 brightness will vary from one color to the next because the forward voltage 
 drop of each color is different. This code was written and calibrated for the 
 red color.

 This code will work with most Arduinos but you may want to re-route some of 
 the pins.

 7 segments
 4 digits
 1 colon
 =
 12 pins required for full control 

 */
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// for my Luckylight KW4-563ASA

int digit1 = 11; //PWM Display pin 12 (digit1 is common anonds A1 from right side)
int digit2 = 10; //PWM Display pin 9 (digit2 is  common A2)
int digit3 = 9; //PWM Display pin 8 (digit3 is common anods A3)
int digit4 = 6; //PWM Display pin 6 (digit4 is common anods, from left side)

//Pin mapping from Arduino to the ATmega DIP28 if you need it
int segA = 2; //Display pin 11
int segB = 3; //Display pin 7
int segC = 4; //Display pin 4
int segD = 5; //Display pin 2
int segE = 12; //Display pin 1
int segF = 7; //Display pin 10
int segG = 8; //Display pin 5
int segDP = 13; // Display pin 3

#include "DHT.h"
#define DHTPIN A2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib


void setup() {

  Wire.begin();
  RTC.begin();
// RTC.adjust(DateTime(__DATE__, __TIME__));
// if you need set clock... just remove // from line above this

// part code for flashing LED
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
// Wire.write(0x00); // turns the SQW pin off
 Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
// Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz

Wire.endTransmission();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
  
 dht.begin();

  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  
//  pinMode(13, OUTPUT);

 Serial.begin(9600);
 Serial.println("test for niq_ro");
}

void loop() {
digitalWrite(segDP, HIGH);
  DateTime now = RTC.now();
   int timp = now.hour()*100+now.minute();
//   int timp = (now.minute(), DEC);
//   displayNumber(12); // this is number to diplay
//   int timp = 1234;
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(" -> ");
  Serial.print(timp);
  Serial.println(" !");
  
   int h = dht.readHumidity();
   int t = dht.readTemperature();

   for(int i = 1000 ; i >0  ; i--) {
     displayNumber(t); // this is number to diplay
   }
   
   for(int i = 1000 ; i >0  ; i--) {
     displayNumber1(h); // this is number to diplay
   }
   
   for(int i = 1000 ; i >0  ; i--) {
     if (timp > 1000) displayNumber01(timp); 
     else displayNumber02(timp); 
   } 
  
}


//Given a number, we display 10:22
//After running through the 4 numbers, the display is left turned off

//Display brightness
//Each digit is on for a certain amount of microseconds
//Then it is off until we have reached a total of 20ms for the function call
//Let's assume each digit is on for 1000us
//Each digit is on for 1ms, there are 4 digits, so the display is off for 16ms.
//That's a ratio of 1ms to 16ms or 6.25% on time (PWM).
//Let's define a variable called brightness that varies from:
//5000 blindingly bright (15.7mA current draw per digit)
//2000 shockingly bright (11.4mA current draw per digit)
//1000 pretty bright (5.9mA)
//500 normal (3mA)
//200 dim but readable (1.4mA)
//50 dim but readable (0.56mA)
//5 dim but readable (0.31mA)
//1 dim but readable in dark (0.28mA)

void displayNumber(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW


  for(int digit = 4 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
      digitalWrite(digit1, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      lightNumber(11); // display degree symbol
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      lightNumber(12); // display C letter
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    }
     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
}

void displayNumber1(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW


  for(int digit = 4 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
      digitalWrite(digit1, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      lightNumber(10); // display degree symbol
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      lightNumber(13); // display C letter
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    }
     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
}

void displayNumber01(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 4 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     digitalWrite(segDP, HIGH);
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
}

void displayNumber02(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 4 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     digitalWrite(segDP, HIGH);
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
}


//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

#define SEGMENT_ON  LOW
#define SEGMENT_OFF HIGH

  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // all segment are ON
  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
  // degree symbol made by niq_ro
  case 11:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // C letter made by niq_ro
  case 12:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
  // H letter made by niq_ro
  case 13:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
  }
}

poate arata asa:
 /*  
  6-13-2011  
  Spark Fun Electronics 2011  
  Nathan Seidle  
  This code is public domain but you buy me a beer if you use this and we meet   
  someday (Beerware license).  
  4 digit 7 segment display:  
  http://www.sparkfun.com/products/9483  
  Datasheet:   
  http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf  
  This is an example of how to drive a 7 segment LED display from an ATmega  
  without the use of current limiting resistors. This technique is very common   
  but requires some knowledge of electronics - you do run the risk of dumping   
  too much current through the segments and burning out parts of the display.   
  If you use the stock code you should be ok, but be careful editing the   
  brightness values.  
  This code should work with all colors (red, blue, yellow, green) but the   
  brightness will vary from one color to the next because the forward voltage   
  drop of each color is different. This code was written and calibrated for the   
  red color.  
  This code will work with most Arduinos but you may want to re-route some of   
  the pins.  
  7 segments  
  4 digits  
  1 colon  
  =  
  12 pins required for full control   
  */  
 // modified connexion by niq_ro from http://nicuflorica.blogspot.com  
 // for my Luckylight KW4-563ASA  
 // dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf  
 int digit1 = 11; //PWM Display pin 12 (digit1 is common anonds A1 from right side)  
 int digit2 = 10; //PWM Display pin 9 (digit2 is common A2)  
 int digit3 = 9; //PWM Display pin 8 (digit3 is common anods A3)  
 int digit4 = 6; //PWM Display pin 6 (digit4 is common anods, from left side)  
 //Pin mapping from Arduino to the ATmega DIP28 if you need it  
 //http://www.arduino.cc/en/Hacking/PinMapping  
 int segA = 2; //Display pin 11  
 int segB = 3; //Display pin 7  
 int segC = 4; //Display pin 4  
 int segD = 5; //Display pin 2  
 int segE = 12; //Display pin 1  
 int segF = 7; //Display pin 10  
 int segG = 8; //Display pin 5  
 int segDP = 13; // Display pin 3  
 #include "DHT.h"  
 #define DHTPIN A2   // what pin we're connected to  
 #define DHTTYPE DHT11  // DHT 11   
 DHT dht(DHTPIN, DHTTYPE);  
 #include <Wire.h>  
 #include "RTClib.h"  
 RTC_DS1307 RTC;  
 // Date and time functions using a DS1307 RTC connected via I2C and Wire lib  
 // original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/  
 // add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/  
 void setup() {  
  Wire.begin();  
  RTC.begin();  
 // RTC.adjust(DateTime(__DATE__, __TIME__));  
 // if you need set clock... just remove // from line above this  
 // part code for flashing LED  
 Wire.beginTransmission(0x68);  
 Wire.write(0x07); // move pointer to SQW address  
 // Wire.write(0x00); // turns the SQW pin off  
  Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz  
 // Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz  
 Wire.endTransmission();  
  if (! RTC.isrunning()) {  
   Serial.println("RTC is NOT running!");  
   // following line sets the RTC to the date & time this sketch was compiled  
   RTC.adjust(DateTime(__DATE__, __TIME__));  
  }  
  dht.begin();  
  pinMode(segA, OUTPUT);  
  pinMode(segB, OUTPUT);  
  pinMode(segC, OUTPUT);  
  pinMode(segD, OUTPUT);  
  pinMode(segE, OUTPUT);  
  pinMode(segF, OUTPUT);  
  pinMode(segG, OUTPUT);  
  pinMode(segDP, OUTPUT);  
  pinMode(digit1, OUTPUT);  
  pinMode(digit2, OUTPUT);  
  pinMode(digit3, OUTPUT);  
  pinMode(digit4, OUTPUT);  
 // pinMode(13, OUTPUT);  
  Serial.begin(9600);  
  Serial.println("test for niq_ro");  
 }  
 void loop() {  
 digitalWrite(segDP, HIGH);  
  DateTime now = RTC.now();  
   int timp = now.hour()*100+now.minute();  
 //  int timp = (now.minute(), DEC);  
 //  displayNumber(12); // this is number to diplay  
 //  int timp = 1234;  
  Serial.print(now.hour(), DEC);  
  Serial.print(":");  
  Serial.print(now.minute(), DEC);  
  Serial.print(" -> ");  
  Serial.print(timp);  
  Serial.println(" !");  
   int h = dht.readHumidity();  
   int t = dht.readTemperature();  
   for(int i = 1000 ; i >0 ; i--) {  
    displayNumber(t); // this is number to diplay  
   }  
   for(int i = 1000 ; i >0 ; i--) {  
    displayNumber1(h); // this is number to diplay  
   }  
   for(int i = 1000 ; i >0 ; i--) {  
    if (timp > 1000) displayNumber01(timp);   
    else displayNumber02(timp);   
   }   
 }  
 //Given a number, we display 10:22  
 //After running through the 4 numbers, the display is left turned off  
 //Display brightness  
 //Each digit is on for a certain amount of microseconds  
 //Then it is off until we have reached a total of 20ms for the function call  
 //Let's assume each digit is on for 1000us  
 //Each digit is on for 1ms, there are 4 digits, so the display is off for 16ms.  
 //That's a ratio of 1ms to 16ms or 6.25% on time (PWM).  
 //Let's define a variable called brightness that varies from:  
 //5000 blindingly bright (15.7mA current draw per digit)  
 //2000 shockingly bright (11.4mA current draw per digit)  
 //1000 pretty bright (5.9mA)  
 //500 normal (3mA)  
 //200 dim but readable (1.4mA)  
 //50 dim but readable (0.56mA)  
 //5 dim but readable (0.31mA)  
 //1 dim but readable in dark (0.28mA)  
 void displayNumber(int toDisplay) {  
 #define DISPLAY_BRIGHTNESS 500  
 #define DIGIT_ON HIGH  
 #define DIGIT_OFF LOW  
  for(int digit = 4 ; digit > 0 ; digit--) {  
   //Turn on a digit for a short amount of time  
   switch(digit) {  
   case 1:  
    digitalWrite(digit1, DIGIT_ON);  
    lightNumber(toDisplay % 10);  
    toDisplay /= 10;  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   case 2:  
    digitalWrite(digit2, DIGIT_ON);  
    lightNumber(toDisplay % 10);  
    toDisplay /= 10;  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   case 3:  
    digitalWrite(digit3, DIGIT_ON);  
    lightNumber(11); // display degree symbol  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   case 4:  
    digitalWrite(digit4, DIGIT_ON);  
    lightNumber(12); // display C letter  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   }  
    //Turn off all segments  
   lightNumber(10);   
   //Turn off all digits  
   digitalWrite(digit1, DIGIT_OFF);  
   digitalWrite(digit2, DIGIT_OFF);  
   digitalWrite(digit3, DIGIT_OFF);  
   digitalWrite(digit4, DIGIT_OFF);  
 }  
 }   
 void displayNumber1(int toDisplay) {  
 #define DISPLAY_BRIGHTNESS 500  
 #define DIGIT_ON HIGH  
 #define DIGIT_OFF LOW  
  for(int digit = 4 ; digit > 0 ; digit--) {  
   //Turn on a digit for a short amount of time  
   switch(digit) {  
   case 1:  
    digitalWrite(digit1, DIGIT_ON);  
    lightNumber(toDisplay % 10);  
    toDisplay /= 10;  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   case 2:  
    digitalWrite(digit2, DIGIT_ON);  
    lightNumber(toDisplay % 10);  
    toDisplay /= 10;  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   case 3:  
    digitalWrite(digit3, DIGIT_ON);  
    lightNumber(10); // display degree symbol  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   case 4:  
    digitalWrite(digit4, DIGIT_ON);  
    lightNumber(13); // display C letter  
    delayMicroseconds(DISPLAY_BRIGHTNESS);   
    break;  
   }  
    //Turn off all segments  
   lightNumber(10);   
   //Turn off all digits  
   digitalWrite(digit1, DIGIT_OFF);  
   digitalWrite(digit2, DIGIT_OFF);  
   digitalWrite(digit3, DIGIT_OFF);  
   digitalWrite(digit4, DIGIT_OFF);  
 }  
 }   
 void displayNumber01(int toDisplay) {  
 #define DISPLAY_BRIGHTNESS 500  
 #define DIGIT_ON HIGH  
 #define DIGIT_OFF LOW  
  for(int digit = 4 ; digit > 0 ; digit--) {  
   //Turn on a digit for a short amount of time  
   switch(digit) {  
   case 1:  
    digitalWrite(digit1, DIGIT_ON);  
    digitalWrite(segDP, HIGH);  
    break;  
   case 2:  
    digitalWrite(digit2, DIGIT_ON);  
    digitalWrite(segDP, LOW);  
    break;  
   case 3:  
    digitalWrite(digit3, DIGIT_ON);  
    digitalWrite(segDP, HIGH);  
    break;  
   case 4:  
    digitalWrite(digit4, DIGIT_ON);  
    digitalWrite(segDP, HIGH);  
    break;  
   }  
   lightNumber(toDisplay % 10);  
   toDisplay /= 10;  
   delayMicroseconds(DISPLAY_BRIGHTNESS);   
    //Turn off all segments  
   lightNumber(10);   
   //Turn off all digits  
   digitalWrite(digit1, DIGIT_OFF);  
   digitalWrite(digit2, DIGIT_OFF);  
   digitalWrite(digit3, DIGIT_OFF);  
   digitalWrite(digit4, DIGIT_OFF);  
 }  
 }   
 void displayNumber02(int toDisplay) {  
 #define DISPLAY_BRIGHTNESS 500  
 #define DIGIT_ON HIGH  
 #define DIGIT_OFF LOW  
  for(int digit = 4 ; digit > 0 ; digit--) {  
   //Turn on a digit for a short amount of time  
   switch(digit) {  
   case 1:  
    lightNumber(10);   
    digitalWrite(segDP, HIGH);  
    break;  
   case 2:  
    digitalWrite(digit2, DIGIT_ON);  
    digitalWrite(segDP, LOW);  
    break;  
   case 3:  
    digitalWrite(digit3, DIGIT_ON);  
    digitalWrite(segDP, HIGH);  
    break;  
   case 4:  
    digitalWrite(digit4, DIGIT_ON);  
    digitalWrite(segDP, HIGH);  
    break;  
   }  
   lightNumber(toDisplay % 10);  
   toDisplay /= 10;  
   delayMicroseconds(DISPLAY_BRIGHTNESS);   
    //Turn off all segments  
   lightNumber(10);   
   //Turn off all digits  
   digitalWrite(digit1, DIGIT_OFF);  
   digitalWrite(digit2, DIGIT_OFF);  
   digitalWrite(digit3, DIGIT_OFF);  
   digitalWrite(digit4, DIGIT_OFF);  
 }  
 }   
 //Given a number, turns on those segments  
 //If number == 10, then turn off number  
 void lightNumber(int numberToDisplay) {  
 #define SEGMENT_ON LOW  
 #define SEGMENT_OFF HIGH  
  switch (numberToDisplay){  
  case 0:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_ON);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_OFF);  
   break;  
  case 1:  
   digitalWrite(segA, SEGMENT_OFF);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_OFF);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_OFF);  
   digitalWrite(segG, SEGMENT_OFF);  
   break;  
  case 2:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_OFF);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_ON);  
   digitalWrite(segF, SEGMENT_OFF);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  case 3:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_OFF);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  case 4:  
   digitalWrite(segA, SEGMENT_OFF);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_OFF);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  case 5:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_OFF);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  case 6:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_OFF);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_ON);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  case 7:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_OFF);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_OFF);  
   digitalWrite(segG, SEGMENT_OFF);  
   break;  
  case 8:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_ON);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  case 9:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  // all segment are ON  
  case 10:  
   digitalWrite(segA, SEGMENT_OFF);  
   digitalWrite(segB, SEGMENT_OFF);  
   digitalWrite(segC, SEGMENT_OFF);  
   digitalWrite(segD, SEGMENT_OFF);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_OFF);  
   digitalWrite(segG, SEGMENT_OFF);  
   break;  
  // degree symbol made by niq_ro  
  case 11:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_OFF);  
   digitalWrite(segD, SEGMENT_OFF);  
   digitalWrite(segE, SEGMENT_OFF);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  // C letter made by niq_ro  
  case 12:  
   digitalWrite(segA, SEGMENT_ON);  
   digitalWrite(segB, SEGMENT_OFF);  
   digitalWrite(segC, SEGMENT_OFF);  
   digitalWrite(segD, SEGMENT_ON);  
   digitalWrite(segE, SEGMENT_ON);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_OFF);  
   break;  
  // H letter made by niq_ro  
  case 13:  
   digitalWrite(segA, SEGMENT_OFF);  
   digitalWrite(segB, SEGMENT_ON);  
   digitalWrite(segC, SEGMENT_ON);  
   digitalWrite(segD, SEGMENT_OFF);  
   digitalWrite(segE, SEGMENT_ON);  
   digitalWrite(segF, SEGMENT_ON);  
   digitalWrite(segG, SEGMENT_ON);  
   break;  
  }  
 }  

   In mare, este folosita comanda pre din limbajul HTML, dupa cum se vede si in articolul de la http://www.w3schools.com/tags/tag_pre.asp.
   Pentru usurinta editarii se scrie articolul in modul "scrieti",

 apoi se copiaza sketch-ul pe care doriti sa-l postati in fereastra Paste Here Your Source Code de la http://codeformatter.blogspot.ro/
puteti alege niste nici parametrii ai ferestrei si textului
si veti optine codul html care trebuie sa-l inserati in articolul din blog (mai jos si cum va arata):
   Trebuie sa selectati textul din fereastra Copy Formatted Source Code, apoi sa treceti in modul de editare HTML
duceti cursorul la finalul textului de acolo si apasati simultan tastele CTRL si V (adica PASTE/LIPIRE) si apoi mai scrieti un </br>.
   Treceti iar in modul normal "scrieti" si continuati editarea...