#ifndef DiTemperature_H
#define DiTemperature_H
// using Arduino hardware codes outside main:
#include <Arduino.h>
#include "LivinGrimoireLight.h"
/*
lm35 sketch
prints the temperature to the serial monitor
*/
class DiTemperature : public Skill {
private:
int _inPin; // analog pin
public:
DiTemperature(int inPin);
virtual void inOut(byte ear, byte skin, byte eye);
};
#endif
#include <Arduino.h>
#include "DiTemperature.h"
#include "LivinGrimoireLight.h"
DiTemperature::DiTemperature(int inPin)
{
_inPin = inPin;
Serial.begin(9600); // Start serial communication at 9600 baud
}
void DiTemperature::inOut(byte ear, byte skin, byte eye) {
Serial.println("Hello from Arduino!"); // Send a message
delay(1000);
// Serial.print(" \xC2\xB0"); // shows degree symbol
// Serial.println("C");
}
#include <Arduino.h>
#include "DiTemperature.h"
#include "LivinGrimoireLight.h"
DiTemperature::DiTemperature(int inPin)
{
_inPin = inPin;
Serial.begin(9600); // Start serial communication at 9600 baud
}
void DiTemperature::inOut(byte ear, byte skin, byte eye) {
int value = analogRead(_inPin);
float millivolts = (value / 1024.0) * 5000;
float celsius = millivolts / 10;
Serial.print(celsius);
delay(1000);
// Serial.print(" \xC2\xB0"); // shows degree symbol
// Serial.println("C");
}
import serial
import time
def read_serial_data(port='COM3', baud_rate=9600, num_readings=10, timeout=1):
ser = serial.Serial(port, baud_rate, timeout=timeout)
readings = []
for _ in range(num_readings):
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
readings.append(line)
print(line)
time.sleep(1) # Delay between readings
ser.close()
return readings
# Example usage
if __name__ == '__main__':
data = read_serial_data()
import serial
import time
class SerialReader:
def __init__(self, port='COM3', baud_rate=9600, timeout=1):
self.ser = serial.Serial(port, baud_rate, timeout=timeout)
def read_serial_data(self, num_readings=10):
readings = []
for _ in range(num_readings):
if self.ser.in_waiting > 0:
line = self.ser.readline().decode('utf-8').rstrip()
readings.append(line)
print(line)
time.sleep(1) # Delay between readings
return readings
def close(self):
self.ser.close()
# Example usage
if __name__ == '__main__':
reader = SerialReader()
data = reader.read_serial_data()
reader.close()
import serial
import time
import atexit
class SerialReader:
def __init__(self, port='COM3', baud_rate=9600, timeout=1):
self.ser = serial.Serial(port, baud_rate, timeout=timeout)
atexit.register(self.close) # Register the close method to be called on exit
def read_serial_data(self, num_readings=10):
readings = []
for _ in range(num_readings):
if self.ser.in_waiting > 0:
line = self.ser.readline().decode('utf-8').rstrip()
readings.append(line)
print(line)
time.sleep(1) # Delay between readings
return readings
def close(self):
self.ser.close()
# Example usage
if __name__ == '__main__':
reader = SerialReader()
data = reader.read_serial_data()
import serial
import time
import atexit
class SerialReader:
def __init__(self, port='COM3', baud_rate=9600, timeout=1):
self.ser = serial.Serial(port, baud_rate, timeout=timeout)
atexit.register(self.close) # Register the close method to be called on exit
def read_serial_data(self, num_readings=10):
readings = []
for _ in range(num_readings):
if self.ser.in_waiting > 0:
line = self.ser.readline().decode('utf-8').rstrip()
readings.append(line)
print(line)
time.sleep(1) # Delay between readings
return readings
def close(self):
self.ser.close()
# Example usage
if __name__ == '__main__':
reader = SerialReader()
data = reader.read_serial_data()