Go Down

### Topic: First step (SWR-meter). (Read 2419 times)previous topic - next topic

#### willi1

##### Apr 26, 2012, 06:41 pmLast Edit: Apr 26, 2012, 07:39 pm by willi1 Reason: 1
Hello all!

I am very new in programming and this is my first skatch. The goal was to build an SWR-meter. The signals will be read from ADC0 and ADC1, calculate SWR and Power and than displayed on LCD-display. Is any mistakes in my skatch?

Code: [Select]
`#include <LiquidCrystal.h>LiquidCrystal lcd(12,11,5,4,3,2);float forward;float reflection;float val;void setup() {   lcd.begin (16,2);   }void loop() {forward = analogRead(0);reflection = analogRead(1);val = 0;val = forward * 0.098;lcd.clear();lcd.setCursor(3, 0);lcd.print("Power=");lcdPrintFloat(val, 1);lcd.setCursor(5, 1);lcd.print("SWR=");val = 0;val = ((forward + reflection) / (forward - reflection));lcdPrintFloat(val, 1);delay (100);}void lcdPrintFloat (float val, byte precision) {  lcd.print ((long)val);  if (precision > 0) {    lcd.print (".");    unsigned long frac;   unsigned long mult = 1;  byte padding = precision -1; while (precision--)           mult *=10;     if (val >= 0)           frac = (val - int(val)) * mult;      else frac = (int(val) - val) * mult; unsigned long frac1 = frac;while( frac1 /= 10 )        padding--;while( padding-- )        lcd.print("0");lcd.print(frac,DEC);  }}  `

Thanks!

#### MarkT

#1
##### Apr 26, 2012, 07:07 pm
Can you edit your post and re-insert your code using code tags (the # button) so we can see your indentation correctly?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up

Please enter a valid email to subscribe