Hy there guys ..... i have a question and i think it is programming and i don't know where is it
well i have a sanguino barebone and i wish to sand some data over rf transciver and to have a lcd 16x2 showing what i send
BUT when i read a analog pin with ADC the value is 0 to 255 when get to 255 start over again to 0 four times
0V_ 0-255 0-255 0-255 0-255 _for5v
when i quote this line
analogWrite(ledPin2, emontx.A/4);
the value read is 511
here is the code i use
/*
* 6 INTRARI ANALOGICE
* EMITATOR RFM12B
* LCD
*
*/
#include <RF12.h>
#include <JeeLib.h>
#include <PortsLCD.h>
#include <Wire.h>
#include <avr/wdt.h> // Include watchdog library
LiquidCrystal lcd(23, 22, 21, 20, 19, 18);
const byte network = 50; // network group (can be in the range 1-255).
const byte myNodeID = 10; // unique node ID of receiver (1 through 30)
const byte IDreceptor = 11; // unique node ID of receiver (1 through 30)
const byte freq = RF12_868MHZ; // Match freq to module
const byte RF12_NORMAL_SENDWAIT = 0;
int ledPin = 8;
int ledPin2 = 14;
int potA = PA7;
int potB = PA6;
int potC = PA5;
int potD = PA4;
int potX = PA3;
int potF = PA0;
typedef struct {
int A, B, C, D, X, F;} PayloadTX;
PayloadTX emontx;
void setup()
{
wdt_enable(WDTO_4S); // Enable watchdog: max 4 seconds
rf12_initialize(myNodeID, freq, network); // Initialize RFM12
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
//pinMode(potA, INPUT);
//pinMode(potB, INPUT);
//pinMode(potC, INPUT);
//pinMode(potD, INPUT);
//pinMode(potX, INPUT);
//pinMode(potF, INPUT);
lcd.begin(16, 2);
}
void loop()
{
lcd.clear();
emontx.A = analogRead(potA);
emontx.B = analogRead(potB);
emontx.C = analogRead(potC);
emontx.D = analogRead(potD);
emontx.X = analogRead(potX);
emontx.F = analogRead(potF);
afisareLCD();
analogWrite(ledPin2, emontx.A/4);
int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}
rf12_sendStart(IDreceptor, &emontx, sizeof emontx);
digitalWrite(ledPin, HIGH);
delay(20);
digitalWrite(ledPin, LOW);
wdt_reset(); // Reset watchdog
rf12_sendWait(RF12_NORMAL_SENDWAIT); // wait for send completion
}
void afisareLCD (void)
{
lcd.setCursor(0,0); //primul rand
lcd.print("A");
lcd.print(emontx.A);
lcd.setCursor(5,0); //primul rand
lcd.print("B");
lcd.print(emontx.B);
lcd.setCursor(10,0); //primul rand
lcd.print("C");
lcd.print(emontx.C);
lcd.setCursor(0,1); //primul rand
lcd.print("D");
lcd.print(emontx.D);
lcd.setCursor(5,1); //primul rand
lcd.print("X");
lcd.print(emontx.X);
lcd.setCursor(10,1); //primul rand
lcd.print("F");
lcd.print(emontx.F);
//lcd.setCursor(0,1); //al doilea rand
//lcd.print("TX-");
//lcd.print(sizeof emontx);
//lcd.print(emontx[i]);
}
Where do u think my problems comes
int potX = PA3; i tried = A3, =3
if i use other pin that i know it returns 1023 .... it returns 255 that's why i think is a software bug