Advertisement
Guest User

Untitled

a guest
Jun 20th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. /*
  2.  *  ------Geiger Tube board (Arduino Code) Example--------
  3.  *
  4.  *  Explanation: This example shows how to get the signal from the Geiger Tube
  5.  *  in Arduino, we use one of the Arduino interrupt pins (PIN2).
  6.  *  We count the time (ms) between two pulses of the Geiger tube.
  7.  *
  8.  *  Copyright (C) 2011 Libelium Comunicaciones Distribuidas S.L.
  9.  *  http://www.libelium.com
  10.  *
  11.  *  This program is free software: you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation, either version 2 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23.  *
  24.  *  Version:        0.3
  25.  *  Design:     Marcos Yarza, David Gascon
  26.  *  Implementation: Marcos Yarza
  27.  */
  28.  
  29. // Conversion factor - CPM to uSV/h
  30. #include <PString.h>
  31.  
  32. #define CONV_FACTOR 0.00812
  33.  
  34. // Variables
  35. //int ledArray [] = {10,11,12,13,9};
  36. int geiger_input = 2;
  37. long count = 0;
  38. long countPerMinute = 0;
  39. long timePrevious = 0;
  40. long timePreviousMeassure = 0;
  41. long time = 0;
  42. long countPrevious = 0;
  43. float radiationValue = 0.0;
  44. long radValue=0;
  45. char outString[50];
  46. PString transmission(outString,50);
  47.  
  48. void setup(){
  49.   pinMode(geiger_input, INPUT);
  50.   digitalWrite(geiger_input,HIGH);
  51.   Serial.begin(115200);
  52.   attachInterrupt(0,countPulse,FALLING);
  53. }
  54.  
  55. void loop(){
  56.  
  57.   if (millis()-timePreviousMeassure > 10000){
  58.     detachInterrupt(0);
  59.     countPerMinute = 6*count;
  60.     radiationValue = countPerMinute * CONV_FACTOR;
  61.     count = 0;
  62.     transmission.begin();
  63.     transmission += "$RDATA,";
  64.     transmission += countPerMinute;
  65.     transmission += ",cpm,";
  66.     transmission += radiationValue;
  67.     transmission += ",uSv/h~";
  68.     /*tempMission ="$";
  69.      tempMission += "cpm =";
  70.      tempMission += countPerMinute,DEC;
  71.      tempMission += " - ";
  72.      tempMission += "uSv/h = ";
  73.      radValue = radiationValue;
  74.      tempMission += radValue,DEC;
  75.      transmission = tempMission;*/
  76.  
  77.     timePreviousMeassure = millis();
  78.     Serial.println(outString);
  79.     attachInterrupt(0,countPulse,FALLING);
  80.   }
  81.  
  82.  
  83. }
  84.  
  85. void countPulse(){
  86.   detachInterrupt(0);
  87.   count++;
  88.   while(digitalRead(2)==0){
  89.     Serial.flush();
  90.   }
  91.   attachInterrupt(0,countPulse,FALLING);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement