I'am building simple dac that converts digital signal to analog signal. I'm using arduino mega
I figured out that port manipulation thing on mega (which is kinda confusing). Now I'm trying to input a voltage value on serial monitor to take an output through my circuit.
Thats my circuit,ignore that little wire between resistors
int voltage_input; //voltage value
//int x=0.01960784313725490196078431372549; // i'll use it later application
void setup(){
Serial.begin(9600);
Serial.println("Pwm to Analog voltage output");
//set digital pins 42-49 as outputs
for (int i=42;i<50;i++){
pinMode(i,OUTPUT);
}
}
void loop(){
if (Serial.available()>0)
{
voltage_input = Serial.parseInt();
}
if(voltage_input >0){Serial.println(voltage_input);}
PORTL = voltage_input ;
delay(1000);
}
Problem is parseInt functions time-out blocking me. when i entered a value my multimeter shows that but after 1 sec it disappears, voltage drops to zero.
boolean didItAlready = false;
void loop(){
if(Serial.available() && !didItAlready){
val = Serial.read();
didItAlready = true
}
// do whatever with your read value
}
on the other hand i adapted this code to my code. it holds the value but i can't enter a new value, it shows the first value and i don't know how to manage.
I can't figure it out anyways, all the topics of "integer to ASCII conversation,parseInt,Serial Communication and yes i read Serial Input Basics - updated - Introductory Tutorials - Arduino Forum " now are purple on my google search.
I just need adjusting my voltage through serial monitor thats all.
I'm kinda new on arduino things and sorry for my bed england...