Hallo Iedereen,
Ik probeer een klok - thermometer met een 7 segment display. Ik probeer het geheel in blokjes op te bouwen.
momenteel wil in enkel de enkeltallen van de seconden op een enkel 7 segment display weergeven ( het display moet uiteindelijk ge-multiplexed worden daarom dat ik de eenheden, tientallen enz. wil scheiden.
bij deze berekening krijg ik een foutmelding en ik begrijp niet goed waarom :
: 1.6.6 (Mac OS X), Board:"Arduino Leonardo"
/Users/koenpeeters/Documents/Arduino/sketch_jan26a_DHT11_DS3231_BuildUp/sketch_jan26a_DHT11_DS3231_BuildUp.ino: In function 'void loop()':
sketch_jan26a_DHT11_DS3231_BuildUp:159: error: invalid operands of types '' and 'int' to binary 'operator/'
int tens = second / 10;
** ^**
sketch_jan26a_DHT11_DS3231_BuildUp:160: error: invalid operands of types '' and 'int' to binary 'operator-'
int singles = second - ( tens*10);
** ^**
exit status 1
invalid operands of types '' and 'int' to binary 'operator/'
#include <DS3232RTC.h>
#include <Time.h>
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#include <Wire.h>
#define DHTPIN 4 // what digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
// Pin connected to ST_CP of 74HC595
int latchPin = 8;//8
// Pin connected to SH_CP of 74HC595
int clockPin = 9; //9
// Pin connected to DS of 74HC595
int dataPin = 10; //10
byte dataArray[12];
byte dataToSend[3];
int tens;
int singles;
void setup() {
dht.begin();
Wire.begin();
Serial.begin(9600);
//Serial.println("DHTxx test!");
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
RTC.squareWave(SQWAVE_1_HZ);
pinMode(latchPin, OUTPUT);
//Bitmasks for the symbols to display on the 7 segment display
dataArray[0] = 0x3F; //00111111 0
dataArray[1] = 0x06; //00000110 1
dataArray[2] = 0x5B; //01011011 2
dataArray[3] = 0x4F; //01001111 3
dataArray[4] = 0x66; //01100110 4
dataArray[5] = 0x6D; //01101101 5
dataArray[6] = 0x7D; //01111101 6
dataArray[7] = 0x07; //00000111 7
dataArray[8] = 0x7F; //01111111 8
dataArray[9] = 0x6F; //01101111 9
dataArray[10] = 0x33; //00110011 °
dataArray[11] = 0x39; //00111001 C
}
void loop() {
// Wait a few seconds between measurements.
//delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//float f = dht.readTemperature(true);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C ");
digitalClockDisplay();
//delay(1000);
int tens = second / 10;
int singles = second - ( tens*10);
dataToSend[0] += dataArray[7];
shiftOut(dataPin, clockPin, dataToSend[0]);
//shiftOut(dataPin, clockPin, dataToSend[1]);
//shiftOut(dataPin, clockPin, dataToSend[2]);
digitalWrite(latchPin, 1);
delay(500);
}
void digitalClockDisplay(void)
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(' ');
Serial.print(day());
Serial.print(' ');
Serial.print(month());
Serial.print(' ');
Serial.print(year());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(':');
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}