Siirry takaisin
LISÄTIEDOT
TUOTTEEN LISÄTIEDOT |
TUOTE |
HINTA |
TILAA |
NTC10Kohm - VISHAY NTC THERMISTOR, 10KOHM, 10 kpl:n erä.3.- Euro sopivat esim. Arduinolle. |
|
0,50 € (0,40 €) |
|
|
Tuotteen kuvaus:
http://wch.cn/download/CH341SER_ZIP.html
Suoritin
ATmega2560
Käyttöjännite
5V
Käyttöjännite (suositeltu)
7-12V
Digitaalisten ulostulojen määrä
54 (joista 15 kpl voidaan käyttää PWM-ulostuloina)
PWM Digitaaliset I/O ulostulot
15 kpl
Analogiset sisääntulot
16 kpl
DC-virta per I/O Pin
20 mA
DC-virta 3.3V Pin:lle
50 mA
Flash muisti
256 KB (ATmega328P), josta 8 KB käyttää bootloader
SRAM
8 KB
EEPROM
4 KB
Kellotaajuus
16 MHz
Pituus
101,52 mm
Leveys
53,3 mm
Paino
37 g
Mukana ohjelmointikaapeli
#include
#include
#include
#define LDRPIN A1
#define POTPIN A0
#define HALPIN A3
// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A1; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
LiquidCrystal lcd(12,11,5,4,3,2);
OneWire ds(8);
Servo servo;
uint8_t STEPPINS[4] ={50,52,51,53};
void setup() {
int i;
// initialize serial communications at 9600 bps:
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println(LED_BUILTIN);
lcd.begin(20,4);
lcd.print("Hello Bebek");
Serial.print("Init STEP MOTOR");
for(i=0;i<4;i++){
pinMode(STEPPINS[i],OUTPUT);
Serial.println(STEPPINS[i]);
}
for(i=0;i<4;i++){
Serial.println(STEPPINS[i]);
digitalWrite(STEPPINS[i],1);
delay(500);
digitalWrite(STEPPINS[i],0);
delay(500);
lcd.print(".");
}
Serial.print("Init DS18B20:");
Serial.println(ds1820(1));
Serial.println("Init Servo");
servo.attach(9);
Serial.println("Init pir pin 7");
pir(0);
}
uint8_t *DDR[8] = {&DDRA,&DDRB,&DDRC,&DDRD,&DDRE,&DDRF,&DDRG,&DDRH};
void exec(char *bf)
{
Serial.println(bf);
char ch=*bf++;
char *cp=bf;
int v,v2;
while(isspace(*cp)) cp++;
v = strtol(cp,&cp,0);
v2 = strtol(cp,&cp,0);
switch(ch){
case 's':pinMode(v,OUTPUT);digitalWrite(v,1);break;
case 'c':pinMode(v,OUTPUT);digitalWrite(v,0);break;
case 'g':pinMode(v,INPUT_PULLUP);Serial.println(digitalRead(v));break;
case 'a':pinMode(v,INPUT_PULLUP);Serial.println(analogRead(v));break;
case 'p':analogWrite(v,v2);break;
case 'A':if(*bf) {DDRA=0xff;PORTA=v;}else{DDRA=0x00;Serial.print("0x");Serial.println(PORTA,HEX);};break;
case 'B':if(*bf) {DDRB=0xff;PORTB=v;}else{DDRB=0x00;Serial.print("0x");Serial.println(PORTB,HEX);};break;
case 'C':if(*bf) {DDRC=0xff;PORTC=v;}else{DDRC=0x00;Serial.print("0x");Serial.println(PORTC,HEX);};break;
case 'D':if(*bf) {DDRD=0xff;PORTD=v;}else{DDRD=0x00;Serial.print("0x");Serial.println(PORTD,HEX);};break;
case 'E':if(*bf) {DDRE=0xff;PORTE=v;}else{DDRE=0x00;Serial.print("0x");Serial.println(PORTE,HEX);};break;
case 'F':if(*bf) {DDRF=0xff;PORTF=v;}else{DDRF=0x00;Serial.print("0x");Serial.println(PORTF,HEX);};break;
case 'G':if(*bf) {DDRG=0xff;PORTG=v;}else{DDRG=0x00;Serial.print("0x");Serial.println(PORTF,HEX);};break;
case 'H':if(*bf) {DDRH=0xff;PORTH=v;}else{DDRH=0x00;Serial.print("0x");Serial.println(PORTH,HEX);};break;
default:
Serial.println("(c) martti@lumme.org should be added when copied " __DATE__);
}
Serial.print("%");
}
void ldr()
{
int v = analogRead(LDRPIN);
lcd.setCursor(0,1);
lcd.print("LDR:");
lcd.print(v);lcd.print(" ");
}
void pot()
{
int v = analogRead(POTPIN);
lcd.setCursor(0,2);
lcd.print("POT:");
lcd.print(v);lcd.print(" ");
}
void hal()
{
int v = analogRead(HALPIN);
lcd.setCursor(0,3);
lcd.print("HAL:");
lcd.print(v);lcd.print(" ");
}
int timer;
void tim()
{
lcd.setCursor(13,0);
lcd.print("TIM:");
lcd.print(timer++);
}
void cmd()
{
static char bf[80];
static uint8_t bp=0;
while(Serial.available()){
char ch = Serial.read();
switch(ch){
case '\n':
case '\r':
bf[bp] = 0;
bp = 0;
exec(bf);
break;
default:
bf[bp++] = ch;
if(bp>=sizeof(bf)-1) bp = sizeof(bf)-1;;
}
}
}
int dir=0;
int vel=1;
void stepper()
{
static long steptime=0;
static int phase=0x7;
int i;
if(!timeout(steptime)) return;
steptime = timeset(1);
if(dir){
phase <<= 1;
if(phase & 0x100) phase++;
}else{
i= phase&1;
phase >>=1;
if(i) phase |= 0x80;
else phase &= ~0x80;
}
for(i=0;i<4;i++) digitalWrite(STEPPINS[i],(phase>>(i+i))&1);
}
void pir(int run)
{
static unsigned int last=0;
static int alarms=0;
if(!run) pinMode(7,INPUT_PULLUP);
last<<=1;
last += !digitalRead(7);
if(last!=15) return;
alarms++;
lcd.setCursor(10,2);
lcd.print(alarms);
lcd.print("#");
}
int ds1820(int show) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
int16_t temp;
if ( !ds.search(addr)) {
if(show)Serial.print("No more addresses.\n");
ds.reset_search();
// delay(250);
return;
}
if(show){
Serial.print("R=");
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
if ( addr[0] != 0x28) {
Serial.print("Device is not a DS18B20 family device.\n");
return;
}
// The DallasTemperature library can do all this work for you!
}
// delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
if(show){
Serial.print("P=");
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print( OneWire::crc8( data, 8), HEX);
Serial.println();
}
temp = data[1];
temp<<=8;
temp+=data[0];
Serial.println(temp);
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
lcd.setCursor(10,1);
lcd.print((float)temp/16);
lcd.print(" C ");
return temp;
}
int timeout(long l){
l = millis()-l;
return l>0;
}
long timeset(long l){
return millis()+l;
}
void loop() {
static long ticktime;
cmd();
if(timeout(ticktime)){
ticktime=timeset(1000);
tim();
ldr();
pot();
hal();
ds1820(1);
if(timer%5==0) dir^=1;
}
servo.write(analogRead(POTPIN)>>4);
stepper();
pir(1);
}
|
|
|
|
|
|
|
|
|