/* Spinetester v1.0 Using Arduino Duemilanove with ATMega328P --> 1kbyte SRAM --> Using 512 Pixel: 512*2byte = 1024byte 3 Buttons on Pins: PD6 - kalibrieren PD7 - messen PB0 - pfeilart PC4 - Uart on/off CCD_CONTROL pins: PB1 - rog PB2 - clock PC0 - ccd output signal LASER pin: PB5 LCD pins: PD2 - D7 PD3 - D6 PD4 - D5 PD5 - D4 PB3 - E PB4 - RS */ #include #define PIXEL 512 #define COMPLETE 2087 const uint8_t EXP_HOLZPFEIL = 1000; const uint8_t EXP_CARBONPFEIL = 2000; /*********define Pins*********/ /*output from ccd*/ #define ccd A0 // = PC0 /*pins to control ccd and laser*/ #define rog 9 // = PB1 #define clock 10 // = PB2 #define laser 13 // = PB5 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //RS,E,D4,D5,D6,D7 /*pins for buttons*/ #define kalibrieren_pin 6 // = PD6 #define messen_pin 7 // = PD7 #define pfeilart_pin 8 // = PB0 //#define uart_switch A4 // = PC4 volatile uint8_t pressed = 0; uint8_t pfeilart = 0; uint8_t kalibrieren = 0; uint8_t messen = 0; int ccd_array [PIXEL]; uint8_t j = 0; int x = 0; /* read capacitive pin */ #include "pins_arduino.h" // Arduino pre-1.0 needs this uint8_t readCapacitivePin (uint8_t pinToMeasure, uint8_t variable, uint8_t maxi) { // Variables used to translate from Arduino to AVR pin naming volatile uint8_t* port; volatile uint8_t* ddr; volatile uint8_t* pin; // Here we translate the input pin number from // Arduino pin number to the AVR PORT, PIN, DDR, // and which bit of those registers we care about. byte bitmask; port = portOutputRegister(digitalPinToPort(pinToMeasure)); ddr = portModeRegister(digitalPinToPort(pinToMeasure)); bitmask = digitalPinToBitMask(pinToMeasure); pin = portInputRegister(digitalPinToPort(pinToMeasure)); // Discharge the pin first by setting it low and output *ddr |= bitmask; *port &= ~(bitmask); // Make the pin an input with the internal pull-up on *ddr &= ~(bitmask); *port |= bitmask; delayMicroseconds(1); if(*pin & bitmask) { pressed = 0; } else { if(!(pressed)) { pressed = 1; if(variable29 && i<2081) { j++; digitalWrite(clock,LOW); //RESET CLOCK analogRead(A1); //low phase so lange wie high phase digitalWrite(clock,HIGH); //SET CLOCK if(j == 4) { ccd_array[x] = analogRead(ccd); j=0; x++; } } } } /* Function to display the graph with logview */ void logView (int val1,int val2) { Serial.print("$1;1;0;"); Serial.print(val1,DEC); Serial.print(";"); Serial.print(val2,DEC); Serial.print(";0"); Serial.println(13,DEC); } void setup () { Serial.begin(115200); lcd.begin(16, 2); analogReference(DEFAULT); //AREF = 5V //GPIO standards pinMode(ccd,INPUT); pinMode(rog,OUTPUT); pinMode(clock,OUTPUT); pinMode(laser,OUTPUT); digitalWrite(rog,HIGH); digitalWrite(clock,HIGH); digitalWrite(laser,LOW); } void loop () { pfeilart = readCapacitivePin(pfeilart_pin,pfeilart,1); if((kalibrieren <= 1) && (messen <= 1)) { if (pfeilart == 0) { //Holzpfeil lcd.setCursor(3,1); lcd.print("Holzpfeil"); } else { //Carbonpfeil lcd.setCursor(2,1); lcd.print("Carbonpfeil"); } } kalibrieren = readCapacitivePin(kalibrieren_pin,kalibrieren,1); /** CALIBRATING **/ if (kalibrieren == 1) { lcd.setCursor(3,1); lcd.print("Kalibrieren"); if (pfeilart == 0) { ccd_routine(EXP_HOLZPFEIL); } else { ccd_routine(EXP_CARBONPFEIL); } for(int i=0;i to get all data of all pixel! } lcd.setCursor(5,1); lcd.print("Kalibriert!"); kalibrieren = 0; } /* MEASURING */ messen = readCapacitivePin(messen_pin,messen,1); if (messen == 1) { lcd.setCursor(5,1); lcd.print("Messen"); if (pfeilart == 0) { ccd_routine(EXP_HOLZPFEIL); } else { ccd_routine(EXP_CARBONPFEIL); } for(int i=0;i to get all data of all pixel! } lcd.setCursor(5,1); lcd.print("Gemessen!"); messen = 0; } } //end loop