Components and supplies
Flash adapter
Logic Level FET N-Channel
Resistor (value depending of the LCD backlight)
Single Turn Potentiometer- 10k ohms
9V Battery Clip
Resistor 47 ohms 1 W
Solderless Breadboard Full Size
Electronic flash
3.5 mm female jack plug mono
Standard LCD - 16x2 White on Blue
Pushbutton 6 mm
Arduino Nano Every
9 LED torch
Small Signal Diode, Switching
9V battery (generic)
Tools and machines
Soldering iron (generic)
Project description
Code
Untitled file
c_cpp
1[code] 2 3 /* A serious stroboscope */ 4 5 /*------------ The hardware ------------ */ 6/* 7This stroboscope uses a standard 16x2 Liquid Crystal Display 8It is connected in the same way as in the examples of the 9LiquidCrystal library, except for the backlight whose brightness 10can be adjusted by a potentiometer (P1). This potentiometer 11delivers a 0 - 5 V voltage to the analog input A7, and the LED- 12pin of the backlight is driven by the PWM output pin D10 through 13an N-channel MOSFET (Q1) and a resistor (R1). The LED+ pin of 14the backlight is connected to the 9V power supply. 15*/ 16#include <LiquidCrystal.h> 17 18/* 19Initialize the library by associating any needed LCD interface 20pin with the arduino pin number it is connected to 21*/ 22const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 23LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 24const int backLightPotPin=A7; 25const int backLightPin=10; 26 27/* 28The period and the duration of the flash can be adjusted via 29four pushbuttons PB0 to PB4 which are connected to the pins 30D6 - D9 of the arduino. 31*/ 32const int pushButtonPin[4]={6, 7, 8, 9}; 33 34/* 35The flash is delivered by a 9 LEDs torch whose cathode is 36connected to the pin D13 of the arduino through an N-channel 37MOSFET (Q2) and a 47 ohms 1 W resistor (R2). 38The anode of the LED torch is connected to the 9V power supply. 39*/ 40const int ledPin=13; 41 42/* 43Optionally, the stroboscope can drive an electronic flash whose 44central contact is connected to the A6 pin through an N-channel 45MOSFET (Q3). 46*/ 47const int electronicFlashPin=A6; 48 49/* 50The stroboscope can be synchronized by connecting the pin A5 to 51the ground. 52*/ 53const int synchroPin=A5; 54 55 56 /* ------ The constants and global variables ------ */ 57 58/* 59Characteristics of the flash in microseconds, 60resolution 100 microseconds 61*/ 62unsigned long flashPeriod=500000, flashDuration=100000; 63 64/* 65Measurement of elapsed time to control the flash 66*/ 67unsigned long lastTime=0, actualTime, elapsed; 68 69/* 70Management of the pushbuttons : each pushbutton increases or 71decreases one of the values of the flash, and when the button 72is pressed during some seconds, the value increases or decreases 73faster and faster. 74These constants determine the behaviour of the pushbuttons. 75 76After "debounceTime" (50 ms), the value is increased or 77decreased once by 100 microsec. and the flag "incremented" is 78set to true to remind it. 79 80After "firstDelayButton" (1000 ms), the value is increased or 81decreased by "firstIncrementButton" (100 microsec.) every 82"firstRepeatButton" (300 ms). 83 84After "secondDelayButton" (4000 ms), the value is increased or 85decreased by "secondIncrementButton" (100 microsec.) every 86"secondRepeatButton" (50 ms). 87 88After "thirdDelayButton" (8000 ms), the value is increased or 89decreased by "thirdIncrementButton" (10000 microsec.) every 90"thirdRepeatButton" (200 ms). 91 92You are encouraged to modify these values in order to adapt the 93behaviour of the pushbuttons to your own comfort. 94*/ 95 96const unsigned firstDelayButton=1000, 97 firstIncrementButton=100, 98 firstRepeatButton=300, 99 secondDelayButton=4000, 100 secondIncrementButton=100, 101 secondRepeatButton=50, 102 thirdDelayButton=8000, 103 thirdIncrementButton=10000, 104 thirdRepeatButton=200; 105 106const unsigned debounceDelay=50; 107bool incremented=false; 108 109/* 110Global variables for the management of the pushbuttons : 111*/ 112int pressedButton; // The number of the 113 // pushbutton being pressed 114 115unsigned long actualButtonsTime=0; // The actual time in ms for 116 // the management of the 117 // pushbuttons 118 119unsigned long buttonPressedTime=0; // The time at which a button 120 // has been pressed 121 122unsigned long elapsedButton; // The time since a button is 123 // beeing pressed 124 125unsigned long incrementTime=0; // The time at which the 126 // value has been increased 127 // or decreased last. 128 129unsigned long incrementDelay=0; // The time since the value 130 // has been increased 131 // or decreased last. 132 133/* ------------ The functions ------------ */ 134 135void displayValues() 136/* 137Display the period and the duration of the flash in ms and 138tenth of ms. 139 */ 140{ 141 int displayedPeriod = flashPeriod/100; 142 int displayedDuration = flashDuration/100; 143 144// Display the period on the LCD 145 lcd.setCursor(6, 0); 146 if (displayedPeriod < 100) 147 lcd.print(" "); 148 if (displayedPeriod < 1000) 149 lcd.print(" "); 150 lcd.print(displayedPeriod/10); 151 lcd.setCursor(10,0); 152 lcd.print(displayedPeriod-10*(displayedPeriod/10)); 153 154// Display the duration on the LCD 155 lcd.setCursor(6, 1); 156 if (displayedDuration < 100) 157 lcd.print(" "); 158 if (displayedDuration < 1000) 159 lcd.print(" "); 160 lcd.print(displayedDuration/10); 161 lcd.setCursor(10,1); 162 lcd.print(displayedDuration-10*(displayedDuration/10)); 163} 164 165bool readButtons() 166/* 167Returns true if one of the four pushbuttons is pressed. 168The number of the pressed button is copied into the global 169variable "pressedButton". 170*/ 171{ 172 for (int i=0; i<4; i++) 173 if (digitalRead(pushButtonPin[i])==LOW) 174 { 175 pressedButton=i; 176 return(true); 177 } 178 return(false); 179} 180 181void increaseDecrease(int increment) 182/* 183According to the pressed pushbutton, the value of "increment" is 184added or substracted to the period or the duration of the flash. 185The values are limited from 0.1 to 999.9 ms. 186*/ 187{ 188 switch(pressedButton) 189 { 190 case 0 : 191 if (flashPeriod < 999900-increment) 192 flashPeriod+=increment; 193 else flashPeriod=999900; 194 break; 195 case 1 : 196 if (flashPeriod > 100+increment) 197 flashPeriod-=increment; 198 else flashPeriod=100; 199 break; 200 case 2 : 201 if (flashDuration < 999900-increment) 202 flashDuration+=increment; 203 else flashDuration=999900; 204 break; 205 case 3 : 206 if (flashDuration > 100+increment) 207 flashDuration-=increment; 208 else flashDuration=100; 209 break; 210 } 211 displayValues(); 212} 213 214void manageIncrementTime(int delayValue, int increment) 215/* 216Manage the delay between increasing or decreasing the flash 217values. When "incrementDelay" reaches "delayValue", the function 218"increaseDecrease" is called. 219*/ 220{ 221 if (actualButtonsTime < incrementTime) 222 incrementDelay=0xFFFFFFFFul-incrementTime+actualButtonsTime; 223 else 224 incrementDelay=actualButtonsTime-incrementTime; 225 if (incrementDelay>=delayValue) 226 { 227 increaseDecrease(increment); 228 incrementTime=actualButtonsTime; 229 } 230} 231 232void setup() { 233 // put your setup code here, to run once: 234for (int i=0; i<4; i++) pinMode(pushButtonPin[i], INPUT_PULLUP); 235pinMode(backLightPin, OUTPUT); 236pinMode(ledPin, OUTPUT); 237pinMode(electronicFlashPin, OUTPUT); 238pinMode(synchroPin, INPUT_PULLUP); 239digitalWrite(ledPin, LOW); 240digitalWrite(electronicFlashPin, LOW); 241 242// set up the LCD's number of columns and rows: 243lcd.begin(16, 2); 244 245// display fix characters on the LCD 246lcd.setCursor(1, 0); 247lcd.print("Per. . ms"); 248lcd.setCursor(1, 1); 249lcd.print("Dur. . ms"); 250displayValues(); 251} 252 253void loop() { 254 // put your main code here, to run repeatedly: 255 256/* 257Turn on and off the LED torch when necessary. Generate a pulse 258towards the electronic flash when the flash period is elapsed. 259*/ 260digitalWrite(electronicFlashPin, LOW); 261actualTime=micros(); 262 263if (digitalRead(synchroPin)==LOW) // Stop flash when synchro is 264 // grounded 265{ 266 lastTime=actualTime; 267 digitalWrite(ledPin, LOW); 268} 269else 270{ 271 if (actualTime < lastTime) 272 elapsed=0xFFFFFFFFul-lastTime+actualTime; 273 else 274 elapsed=actualTime-lastTime; 275 if (elapsed>=flashDuration) digitalWrite(ledPin, LOW); 276 if (elapsed>=flashPeriod) 277 { 278 digitalWrite(ledPin, HIGH); 279 digitalWrite(electronicFlashPin, HIGH); 280 lastTime+=flashPeriod; 281 } 282 283/* 284Manage the pushbuttons. According to the time since a button 285has been pressed, the function "manageIncrementTime" is called. 286*/ 287actualButtonsTime=millis(); 288if (readButtons()) 289{ 290 if (actualButtonsTime<buttonPressedTime) 291 elapsedButton=0xFFFFFFFFul-buttonPressedTime 292 +actualButtonsTime; 293 else 294 elapsedButton=actualButtonsTime-buttonPressedTime; 295 if (elapsedButton>thirdDelayButton) 296 manageIncrementTime(thirdRepeatButton, 297 thirdIncrementButton); 298 else if (elapsedButton>secondDelayButton) 299 manageIncrementTime(secondRepeatButton, 300 secondIncrementButton); 301 else if (elapsedButton>firstDelayButton) 302 manageIncrementTime(firstRepeatButton, 303 firstIncrementButton); 304 else if (elapsedButton>debounceDelay & !incremented) 305 { 306 increaseDecrease(100); 307 incremented=true; 308 } 309} 310else 311{ 312 buttonPressedTime=actualButtonsTime; 313 incremented=false; 314} 315 316/* 317Adjust the brightness of the backlight of the LCD according 318to the position of the potentiometer. 319*/ 320analogWrite(backLightPin, analogRead(backLightPotPin)/4); 321} 322} 323[/code]
Downloadable files
Circuit
Circuit
Schematic diagram
Schematic diagram
Circuit
Circuit
Schematic diagram
Schematic diagram
Comments
Only logged in users can leave comments
frenchy22
0 Followers
•0 Projects
Table of contents
Intro
5
0