import serial
ser = serial.Serial('/dev/ttyUSB0', 9600)
print ser.readline().strip()Home temperature: ${execi 30 python ~/dev/temp.py}°C
ISR(TIMER2_OVF_vect, , ISR_BLOCK ISR_NAKED) { исправил на:ISR(TIMER2_OVF_vect, ISR_BLOCK ISR_NAKED) { компилируется, но проблема осталась.
void loop() {
displ[0] = 1;
displ[1] = 2;
displ[2] = 3;
displ[3] = 4;
}Работает отлично.void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print(incomingByte, BYTE);
}
}
В serial monitor вижу значение температуры. Но вместо 1 2 3 4 уже отображается '1 (зеркальная 9) 9 4. Только закомментирую все, что связано с serial и на индикаторах 1 2 3 4. #include <avr/interrupt.h>
//Снять комментарий для индикаторов с общим катодом
#define OKAT
bool LLOW = LOW;
bool HHIGH = HIGH;
int incomingByte = 0;
int rdigs[] = {12, 11, 10, 9};
int rsegs[] = { 6, 2, 7, 4, 5, 1, 3, 8};
bool digits[15][8] = {
{1, 1, 1, 1, 1, 1, 0, 0}, //0
{0, 1, 1, 0, 0, 0, 0, 0}, //1
{1, 1, 0, 1, 1, 0, 1, 0}, //2
{1, 1, 1, 1, 0, 0, 1, 0}, //3
{0, 1, 1, 0, 0, 1, 1, 0}, //4
{1, 0, 1, 1, 0, 1, 1, 0}, //5
{1, 0, 1, 1, 1, 1, 1, 0}, //6
{1, 1, 1, 0, 0, 0, 0, 0}, //7
{1, 1, 1, 1, 1, 1, 1, 0}, //8
{1, 1, 1, 1, 0, 1, 1, 0}, //9
{0, 0, 0, 0, 0, 0, 0, 0}, //none
{0, 0, 0, 0, 0, 0, 1, 0}, //-
{1, 0, 0, 1, 1, 1, 1, 1}, //E.
{0, 0, 0, 0, 1, 0, 1, 1}, //r.
{1, 1, 1, 1, 1, 1, 0, 1} //0.
};
int cdigit = 0;
int odigit = 0;
int displ[] = {0, 8, 4, 9};
// Подпрограмма прерывания
ISR(TIMER2_OVF_vect) {
// return;
int dig;
if(cdigit < 0 || cdigit > 3) cdigit = 0;
digitalWrite(rdigs[odigit], LLOW);
dig = abs(displ[cdigit]);
#ifdef OKAT
if(displ[cdigit] < 0) digits[dig][7] = 0;
else digits[dig][7] = 1;
#else
if(displ[cdigit] < 0) digits[dig][7] = 1;
else digits[dig][7] = 0;
#endif
for(int i = 0; i < 8; i++) digitalWrite(rsegs[i], !(digits[dig][i]));
digitalWrite(rdigs[cdigit], HHIGH);
odigit = cdigit;
cdigit++;
TCNT2 = 0;
}
void setup() {
int i;
#ifdef OKAT
int j;
LLOW = HIGH;
HHIGH = LOW;
for(i=0; i<15; i++) {
for(j=0; j<8; j++) {
if(digits[i][j]==0) digits[i][j]=1;
else digits[i][j]=0;
}
}
#endif
for(i=0; i<4; i++) {
pinMode(rdigs[i], OUTPUT);
digitalWrite(rdigs[i], LLOW);
}
for(i=0; i<8; i++) {
pinMode(rsegs[i], OUTPUT);
digitalWrite(rsegs[i], LLOW);
}
//Установка делителей таймера
TCCR2A = 0;
TCCR2B |= 1<<CS22;
TCCR2B &= ~((1<<CS21) | (0<<CS20));
TCCR2B &= ~((1<<WGM21) | (1<<WGM20));
//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1<<TOIE2;
//reset timer
TCNT2 = 0;
cleardisplay();
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
Serial.print(incomingByte, BYTE);
}
displ[0] = 1;
displ[1] = 2;
displ[2] = 3;
displ[3] = 4;
}
void cleardisplay() {
for(int i=0; i<4; i++) displ[i] = 10;
}Даже не знаю в чем может быть проблема.
#include <DallasTemperature.h>
DallasTemperature tempSensor; // You may instantiate as many copies as you require.
void setup(void) {
// initialize inputs/outputs
// start serial port
Serial.begin(9600);
tempSensor.begin(12); // Data wire is plugged into port 12 on the Arduino
Serial.println("Dallas Temperature IC Control Library 1.0. Miles Burton");
}
void loop(void) {
// Ask the library whether the device is valid
switch(tempSensor.isValid())
{
case 1:
Serial.println("Invalid CRC");
tempSensor.reset(); // Attempts to redetect IC
return;
case 2:
Serial.println("Not a valid device");
tempSensor.reset(); // Attempts to redetect IC
return;
}
// getTemperature returns a float.
Serial.print(tempSensor.getTemperature());
Serial.print("C");
Serial.println();
Serial.print(DallasTemperature::toFahrenheit(tempSensor.getTemperature())); // Use the inbuild Celcius to Fahrenheit conversion. Returns a float
Serial.print("F");
Serial.println();
}int cdigit = 0;
int odigit = 0;
int displ[] = {0, 8, 4, 9};
aspire89