[136] | 1 | /*
|
---|
| 2 | Copyright (c) 2014 Arduino. All right reserved.
|
---|
| 3 |
|
---|
| 4 | This library is free software; you can redistribute it and/or
|
---|
| 5 | modify it under the terms of the GNU Lesser General Public
|
---|
| 6 | License as published by the Free Software Foundation; either
|
---|
| 7 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 8 |
|
---|
| 9 | This library is distributed in the hope that it will be useful,
|
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 12 | See the GNU Lesser General Public License for more details.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU Lesser General Public
|
---|
| 15 | License along with this library; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include "Arduino.h"
|
---|
| 20 |
|
---|
| 21 | static void Interrupt_Pin3( void ) ; // Ext Int Callback in LOW mode
|
---|
| 22 | static void Interrupt_Pin4( void ) ; // Ext Int Callback in HIGH mode
|
---|
| 23 | static void Interrupt_Pin5( void ) ; // Ext Int Callback in FALLING mode
|
---|
| 24 | static void Interrupt_Pin6( void ) ; // Ext Int Callback in RISING mode
|
---|
| 25 | static void Interrupt_Pin7( void ) ; // Ext Int Callback in CHANGE mode
|
---|
| 26 |
|
---|
| 27 | static uint32_t ul_Interrupt_Pin3 = 0 ;
|
---|
| 28 | static uint32_t ul_Interrupt_Pin4 = 0 ;
|
---|
| 29 | static uint32_t ul_Interrupt_Pin5 = 0 ;
|
---|
| 30 | static uint32_t ul_Interrupt_Pin6 = 0 ;
|
---|
| 31 | static uint32_t ul_Interrupt_Pin7 = 0 ;
|
---|
| 32 |
|
---|
| 33 | int temps = 0;
|
---|
| 34 | int valX = 0;
|
---|
| 35 | int valY = 0;
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | void setup( void )
|
---|
| 39 | {
|
---|
| 40 | // Initialize the digital pin as an output.
|
---|
| 41 | // Pin PIN_LED has an LED connected on most Arduino boards:
|
---|
| 42 | //pinMode( PIN_LED, OUTPUT ) ;
|
---|
| 43 | //digitalWrite( PIN_LED, LOW ) ;
|
---|
| 44 |
|
---|
| 45 | // Initialize the PIN_LED2 digital pin as an output.
|
---|
| 46 | pinMode( PIN_LED2, OUTPUT ) ;
|
---|
| 47 | digitalWrite( PIN_LED2, HIGH ) ;
|
---|
| 48 |
|
---|
| 49 | // Initialize the PIN_LED3 digital pin as an output.
|
---|
| 50 | pinMode( PIN_LED3, OUTPUT ) ;
|
---|
| 51 | digitalWrite( PIN_LED3, LOW ) ;
|
---|
| 52 |
|
---|
| 53 | // Initialize the PIN 2 digital pin as an input.
|
---|
| 54 | pinMode( 2, INPUT ) ;
|
---|
| 55 |
|
---|
| 56 | //**********************************************
|
---|
| 57 | // Clock output on pin 4 for measure
|
---|
| 58 |
|
---|
| 59 | /* pinPeripheral( 4, PIO_AC_CLK ) ; // Clock Gen 0
|
---|
| 60 | pinPeripheral( 5, PIO_AC_CLK ) ; // Clock Gen 1
|
---|
| 61 | pinPeripheral( 13, PIO_AC_CLK ) ; // Clock Gen 3*/
|
---|
| 62 |
|
---|
| 63 | //**********************************************
|
---|
| 64 | Serial5.begin( 115200 ) ; // Output to EDBG Virtual COM Port
|
---|
| 65 |
|
---|
| 66 | // Test External Interrupt
|
---|
| 67 | attachInterrupt( 3, Interrupt_Pin3, LOW ) ;
|
---|
| 68 | attachInterrupt( 4, Interrupt_Pin4, HIGH ) ;
|
---|
| 69 | attachInterrupt( 5, Interrupt_Pin5, FALLING ) ;
|
---|
| 70 | attachInterrupt( 6, Interrupt_Pin6, RISING ) ;
|
---|
| 71 | attachInterrupt( 7, Interrupt_Pin7, CHANGE) ;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | static void led_step1( void )
|
---|
| 75 | {
|
---|
| 76 | // digitalWrite( PIN_LED, LOW ) ; // set the LED on
|
---|
| 77 | digitalWrite( PIN_LED2, LOW ) ; // set the red LED off
|
---|
| 78 | digitalWrite( PIN_LED3, HIGH ) ; // set the red LED off
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | static void led_step2( void )
|
---|
| 82 | {
|
---|
| 83 | // digitalWrite( PIN_LED, HIGH ) ; // set the LED off
|
---|
| 84 | digitalWrite( PIN_LED2, HIGH ) ; // set the red LED on
|
---|
| 85 | digitalWrite( PIN_LED3, LOW ) ; // set the red LED on
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | void loop( void )
|
---|
| 89 | {
|
---|
| 90 | volatile int pin_value=0 ;
|
---|
| 91 | static volatile uint8_t duty_cycle=0 ;
|
---|
| 92 | static volatile uint16_t dac_value=0 ;
|
---|
| 93 |
|
---|
| 94 | // Test digitalWrite
|
---|
| 95 | led_step1() ;
|
---|
| 96 | delay( 500 ) ; // wait for a second
|
---|
| 97 | led_step2() ;
|
---|
| 98 | delay( 500 ) ; // wait for a second
|
---|
| 99 |
|
---|
| 100 | // Test Serial output
|
---|
| 101 | Serial5.write( '-' ) ; // send a char
|
---|
| 102 | Serial5.write( "test1\n" ) ; // send a string
|
---|
| 103 | Serial5.write( "test2" ) ; // send another string
|
---|
| 104 |
|
---|
| 105 | // Test digitalRead: connect pin 2 to either GND or 3.3V. !!!! NOT on 5V pin !!!!
|
---|
| 106 | pin_value=digitalRead( 2 ) ;
|
---|
| 107 | Serial5.write( "pin 2 value is " ) ;
|
---|
| 108 | Serial5.write( (pin_value == LOW)?"LOW\n":"HIGH\n" ) ;
|
---|
| 109 |
|
---|
| 110 | duty_cycle+=8 ;//=(uint8_t)(millis() & 0xff) ;
|
---|
| 111 | analogWrite( 13, duty_cycle ) ;
|
---|
| 112 | analogWrite( 12, duty_cycle ) ;
|
---|
| 113 | analogWrite( 11, duty_cycle ) ;
|
---|
| 114 | analogWrite( 10 ,duty_cycle ) ;
|
---|
| 115 | analogWrite( 9, duty_cycle ) ;
|
---|
| 116 | analogWrite( 8, duty_cycle ) ;
|
---|
| 117 |
|
---|
| 118 | dac_value += 64;
|
---|
| 119 | analogWrite(A0, dac_value);
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | Serial5.print("\r\nAnalog pins: ");
|
---|
| 124 |
|
---|
| 125 | for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ )
|
---|
| 126 | {
|
---|
| 127 |
|
---|
| 128 | int a = analogRead(i);
|
---|
| 129 | Serial5.print(a, DEC);
|
---|
| 130 | Serial5.print(" ");
|
---|
| 131 |
|
---|
| 132 | }
|
---|
| 133 | Serial5.println();
|
---|
| 134 |
|
---|
| 135 | Serial5.println("External interrupt pins:");
|
---|
| 136 | if ( ul_Interrupt_Pin3 == 1 )
|
---|
| 137 | {
|
---|
| 138 | Serial5.println( "Pin 3 triggered (LOW)" ) ;
|
---|
| 139 | ul_Interrupt_Pin3 = 0 ;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | if ( ul_Interrupt_Pin4 == 1 )
|
---|
| 143 | {
|
---|
| 144 | Serial5.println( "Pin 4 triggered (HIGH)" ) ;
|
---|
| 145 | ul_Interrupt_Pin4 = 0 ;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | if ( ul_Interrupt_Pin5 == 1 )
|
---|
| 149 | {
|
---|
| 150 | Serial5.println( "Pin 5 triggered (FALLING)" ) ;
|
---|
| 151 | ul_Interrupt_Pin5 = 0 ;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | if ( ul_Interrupt_Pin6 == 1 )
|
---|
| 155 | {
|
---|
| 156 | Serial5.println( "Pin 6 triggered (RISING)" ) ;
|
---|
| 157 | ul_Interrupt_Pin6 = 0 ;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | if ( ul_Interrupt_Pin7 == 1 )
|
---|
| 161 | {
|
---|
| 162 | Serial5.println( "Pin 7 triggered (CHANGE)" ) ;
|
---|
| 163 | ul_Interrupt_Pin7 = 0 ;
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | // Ext Int Callback in LOW mode
|
---|
| 168 | static void Interrupt_Pin3( void )
|
---|
| 169 | {
|
---|
| 170 | ul_Interrupt_Pin3 = 1 ;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | // Ext Int Callback in HIGH mode
|
---|
| 174 | static void Interrupt_Pin4( void )
|
---|
| 175 | {
|
---|
| 176 | ul_Interrupt_Pin4 = 1 ;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | // Ext Int Callback in CHANGE mode
|
---|
| 180 | static void Interrupt_Pin5( void )
|
---|
| 181 | {
|
---|
| 182 | ul_Interrupt_Pin5 = 1 ;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | // Ext Int Callback in FALLING mode
|
---|
| 186 | static void Interrupt_Pin6( void )
|
---|
| 187 | {
|
---|
| 188 | ul_Interrupt_Pin6 = 1 ;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | // Ext Int Callback in RISING mode
|
---|
| 192 | static void Interrupt_Pin7( void )
|
---|
| 193 | {
|
---|
| 194 | ul_Interrupt_Pin7 = 1 ;
|
---|
| 195 | }
|
---|