Ja, som det kan ses af nedenstående, så skriver jeg nogle gange på Engelsk.
Teksten til højre for // er en kort beskrivelse af hvad hver linje gør.
/* * Voltmeter 0-5V read out on 4 Digit 7-Segment Serial Display. * * Clearing the Display and setting the brightness level. * Test Digit placing. * Test of each segment in each digit. * Test of each Decimal Point, Colon and Apostrophe. * Making Voltmeter conversion to Display for 0-5,000V at 4,88mV step (1024 bit). */ int analogValue0 = 0; // Variable for analog value on A0 int outputValue0 = 0; // Making mapping possible for A0 void setup() // Run once, when the sketch starts { Serial.begin(9600); // Setting communication up at 9600 bps on TX pin at Arduino Uno Serial.write(0x76); // Clear the display and set for Digit 1 delay(500); // Delay for clearing the Display Serial.write(0x7A); // Command for brightness Serial.write(0x01); // Brightness level delay(10); // Delay for changing brightness Serial.write("1234"); // Display read out 1234 delay(500); // Time for Display read out Serial.write("8888"); // Display read out 8888 delay(800); // Time for Display read out Serial.write(0x76); // Clear the display and set for Digit 1 delay(10); // Delay for clearing the Display Serial.write(0x77); // Command for decimal point Serial.write(0x01); // Display read out decimal point digit 1 delay(300); // Time for Display read out Serial.write(0x77); // Command for decimal point Serial.write(0x02); // Display read out decimal point digit 2 delay(300); // Time for Display read out Serial.write(0x77); // Command for decimal point Serial.write(0x10); // Display read out Time Colon delay(300); // Time for Display read out Serial.write(0x77); // Command for decimal point Serial.write(0x04); // Display read out decimal point digit 3 delay(300); // Time for Display read out Serial.write(0x77); // Command for decimal point Serial.write(0x20); // Display read out Apostrophe delay(300); // Time for Display read out Serial.write(0x77); // Command for decimal point Serial.write(0x08); // Display read out decimal point digit 4 delay(300); // Time for Display read out Serial.write(0x77); // Command for decimal point Serial.write(0x40); // Switch off decimal point Serial.write(0x76); // Clear the display and set for Digit 1 delay(500); // Delay for clearing the Display Serial.write(0x77); // Command for decimal point Serial.write(0x01); // Display read out decimal point digit 1 } void loop() // Run over and over again { analogValue0 = analogRead(0); // Reading of the analog input pin A0 outputValue0 = map(analogValue0, 0, 1023, 0, 5000); // 5V with ~ 5mV step if (outputValue0 < 1000) Serial.write("0"); // Writing 0 if voltage is below 1V if (outputValue0 < 100) Serial.write("0"); // Writing 0,0 if voltage is below 0,1V if (outputValue0 < 10) Serial.write("0"); // Writing 0,00 if voltage is below 0,01V Serial.print(outputValue0); // * * * Voltage value * * * delay(250); // Delay before next conversion / read out }
Den opmærksomme læser vil nok bemærke, at der ingen midling er af spændingen.
Grunden til at map går op til 5000 er, at så får vi tre decimaler på.