Professional Documents
Culture Documents
boolean anterior = 0;
boolean actual = 0;
int contador = 0;
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT);
}
boolean debounce(boolean dato_anterior)
{
boolean dato_actual = digitalRead(2);
if (dato_anterior != dato_actual)
{
delay(10);
dato_actual = digitalRead(2);
}
return dato_actual;
}
void loop()
{
actual = debounce(anterior);
if ( anterior == 0 && actual == 1)
{
contador++;
delay (100);
Serial.println(contador);
}
}
anterior = actual;
/*
date: 5/24/11
code by: Jim Lindblom
hardware by: Nate Bernstein
SparkFun Electronics
//License: CC-SA 3.0, feel free to use this code however you'd like.
Please improve upon it! Let me know how you've made it better.
void setup()
{
Serial.begin(9600);
pinMode(statpin, OUTPUT);
void loop()
{
motorGo(0, CW, 0);
//motorGo(0, CCW, 26);
//motorGo(1, CCW, 128);
delay(500);
//motorGo(0, CW, 128);
//delay(1000);
if(analogRead(cspin[0]) > CS_THRESHOLD)
//if ((analogRead(cspin[0]) < CS_THRESHOLD) && (analogRead(cspin[1]) <
CS_THRESHOLD))
digitalWrite(statpin, HIGH);
}
pwm: should be a value between ? and 1023, higher the number, the faster
it'll go
*/
void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
{
if (motor <= 1)
{
if (direct <=4)
{
// Set inA[motor]
if (direct <=1)
digitalWrite(inApin[motor], HIGH);
else
digitalWrite(inApin[motor], LOW);
// Set inB[motor]
if ((direct==0)||(direct==2))
digitalWrite(inBpin[motor], HIGH);
else
digitalWrite(inBpin[motor], LOW);
analogWrite(pwmpin[motor], pwm);
}
}
}
/*
Copyright 2011 Lex Talionis (Lex.V.Talionis at gmail)
This program is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any
later version.
mesure the
time between the rise and fall
of 3 channels of PPM
*/
#include <PinChangeInt.h>
//
http://www.arduino.cc/playground/Main/PinChangeInt
#include <PinChangeIntConfig.h>
#include <TimerOne.h>
//
http://www.arduino.cc/playground/Code/Timer1
MAX_PIN_CHANGE_PINS PIN_COUNT
#define RC_TURN 3
#define RC_FWD 2
#define RC_FIRE 4
byte pin[] = {RC_FWD, RC_TURN, RC_FIRE}; //for maximum efficency thise pins
should be attached
unsigned int time[] = {0,0,0};
in the order listed here
byte state=0;
byte burp=0;
byte cmd=0;
byte i=0;
void setup() {
Serial.begin(115200);
Serial.print("PinChangeInt ReciverReading test");
Serial.println();
Timer1.initialize(2200);
void loop() {
cmd=Serial.read();
report
if (cmd=='p')
{
Serial.print("time:\t");
for (byte i=0; i<PIN_COUNT;i++)
{
Serial.print(i,DEC);
Serial.print(":");
Serial.print(time[i],DEC);
Serial.print("\t");
}
Serial.print(burp, DEC);
Serial.println();
/*
Serial.print("\t");
Serial.print(clockCyclesToMicroseconds(Timer1.pwmPeriod), DEC);
Serial.print("\t");
Serial.print(Timer1.clockSelectBits, BIN);
Serial.print("\t");
Serial.println(ICR1, DEC);*/
}
cmd=0;
switch (state)
{
case RISING: //we have just seen a rising edge
PCintPort::detachInterrupt(pin[i]);
void rise()
{
Timer1.restart();
Timer1.start();
state=RISING;
//
Serial.print('r');
burp++;
void fall()
{
state=FALLING;
time[i]=Timer1.read();
Timer1.stop();
//
}
Serial.print('f');
// Needs Timer1-v2