Hammerheads A3BU code (Drink Dispenser)

We used the A3BU to receive signals from an Arduino Uno, to turn on a green LED, to match ID’s with the name of the person whose finger was scanned, and to power a solenoid motor. This code will consistently check the ADC pin on the A3BU for some kind of voltage signal. If a signal of 120mV or higher is detected, the A3BU will start a counter and increase it for every 100ms that the signal is detected. This counter would become the ID number, transmitted from the Arduino. Once the A3BU detects a Low signal (under 120mV) it would turn on a green LED using a PWM signal. It would also take the ID and match it with the name of the person scanned. These ID’s were programmed into the fingerprint scanner and the names to be matched with the ID’s were hard coded into this code. After the match, the name will be displayed on the LCD screen of the A3BU along with the matching ID. Once this had been done, the A3BU would send a signal to the solenoid motor for a 20 second period in order to dispense the liquid.

 

 

A3BU Code:

#include <asf.h>

#include <stdio.h>

#include <conf_example.h>

#include <util/delay.h>

#include <string.h>



int count = 0; //count will keep track of id number

bool check = false; //check to make sure that the if statement is entered only once at a time



struct pwm_config mypwm[4];

static void adc_handler(ADC_t *adc, uint8_t ch_mask, adc_result_t result)

{

#ifdef CONF_BOARD_OLED_UG_2832HSWEG04

 gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR); //set light on LCD

#endif

char out_str[OUTPUT_STR_SIZE];

result += 10; //make sure result does not go negative

//we were having result go to single digit negatives every now and then which would turn on dispenser



snprintf(out_str, OUTPUT_STR_SIZE, "Voltage: %4d mV", result); // Write voltage from ardunio to display

gfx_mono_draw_string(out_str, 0, 0, &sysfont);   

if(result > 40 ) //If High

{

count++; //increment id number

check = true; //allow dispenser to be active

_delay_ms(15); //delay to check for high from arduino to increment id to the correct id number

}



if(result < 40 && result >= 0 && check == true) //If Low

{

 if ((count-1) == 0) //Cory

 {

  snprintf(out_str, OUTPUT_STR_SIZE, "Cory Lentz id = %i",count-1);

  gfx_mono_draw_string( out_str,0,20,&sysfont);

 }

 if ((count-1) == 1) //Brandon

 {

  snprintf(out_str, OUTPUT_STR_SIZE, "Brandon S. id = %i",count-1);

  gfx_mono_draw_string( out_str,0,20,&sysfont);

 }

 if ((count-1) == 2) //Nick

 {

  snprintf(out_str, OUTPUT_STR_SIZE, "Nick Glass  id = %i",count-1);

  gfx_mono_draw_string( out_str,0,20,&sysfont);

 }

 if ((count-1) == 3) //Dalton

 {

  snprintf(out_str, OUTPUT_STR_SIZE, "Dalton H. id = %i",count-1);

  gfx_mono_draw_string( out_str,0,20,&sysfont);

 }

 

 gfx_mono_draw_string( out_str,0,20,&sysfont);

 

 //Start Green LED and solenoid motor, delay for 20 seconds to dispense, then turn off

 pwm_init(&mypwm[0], PWM_TCC0, PWM_CH_A, 500);//this is SDA on J1 on the A3BU Xplained

 pwm_start(&mypwm[0], 150);

 pwm_init(&mypwm[2], PWM_TCC0, PWM_CH_B, 500);

 pwm_start(&mypwm[2], 150);

 _delay_ms(20000);

 pwm_start(&mypwm[0], 0);

 pwm_start(&mypwm[2], 0);

 gfx_mono_init();

 count = 0; //reset id value

check = false; //ensure if statement is not unwantedly repeated



}

adc_start_conversion(adc, ch_mask);

}



int main(void)

{

struct adc_config      adc_conf;

struct adc_channel_config adcch_conf;



board_init();

sysclk_init();

sleepmgr_init();

struct pwm_config mypwm[4];

irq_initialize_vectors();

cpu_irq_enable();

gfx_mono_init();



// Enable backlight

#ifndef CONF_BOARD_OLED_UG_2832HSWEG04

 ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

#endif



// Initialize configuration structures.

adc_read_configuration(&ADCB, &adc_conf);

adcch_read_configuration(&ADCB, ADC_CH0, &adcch_conf);



adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_8,//Changed resolution from 12 to 8

  ADC_REF_VCC);

adc_set_clock_rate(&adc_conf, 200000UL);

adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);

adc_enable_internal_input(&adc_conf, ADC_INT_TEMPSENSE);



adc_write_configuration(&ADCB, &adc_conf);

adc_set_callback(&ADCB, &adc_handler);



adcch_set_input(&adcch_conf, ADCCH_POS_PIN1, ADCCH_NEG_NONE,

  1);

adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);

adcch_enable_interrupt(&adcch_conf);



adcch_write_configuration(&ADCB, ADC_CH0, &adcch_conf);



// Enable the ADC and start the first conversion.

adc_enable(&ADCB);

adc_start_conversion(&ADCB, ADC_CH0);



do {

 // Sleep until ADC interrupt triggers.

 sleepmgr_enter_sleep();

} while (1);

}