controlling ports
i thought had ports working, got confused. how write 8 bits on consecutive pins d2 - d9?
when input 0 bits 5&6 still high.
code: [select]
byte volt2 = 255;
void setup()
{
serial.begin(9600);
ddrd = b11111100;
ddrb = b00000011;
}
void loop() {
while (serial.available() > 0) {
volt2 = serial.read();
serial.write(volt2);
}
dac2();
}
void dac2(){
portd = (volt2>>2);
portb = (volt2<<6);
}
when input 0 bits 5&6 still high.
i thought had ports working, got confused. how write 8 bits on consecutive pins d2 - d9?when input 0 serial monitor, it's '0', (the ascii character).code: [select]
byte volt2 = 255;
void setup()
{
serial.begin(9600);
ddrd = b11111100;
ddrb = b00000011;
}
void loop() {
while (serial.available() > 0) {
volt2 = serial.read();
serial.write(volt2);
}
dac2();
}
void dac2(){
portd = (volt2>>2);
portb = (volt2<<6);
}
when input 0 bits 5&6 still high.
'0' ascii 0x30, or 0b00110000
(bits 4 , 5 high.)
to convert '0' 0, subtract 0x30.
same goes other ascii digits, multiple digit number, you'll need capture full input string convert, maybe 'atoi()'.
Arduino Forum > Using Arduino > Programming Questions > controlling ports
arduino
Comments
Post a Comment